示例#1
0
	TEST(Tar, read) {

		File folder = File(__FILE__).getParent();
		File file = File(folder, "test.tar");

		FileInputStream fis = FileInputStream(file);
		UnTarStream tar(&fis);

		unsigned int cnt = 0;
		while (tar.hasNext()) {

			UnTarEntry ute = tar.next();
			std::cout << ute.header.getTimestamp() << std::endl;

			// read to vector
			std::vector<uint8_t> vec = ute.stream.readCompletely();

			ASSERT_EQ(ute.header.getSize(), vec.size());

			if (cnt == 2) {
				std::string str((char*)vec.data(), vec.size());
				ASSERT_EQ("hallo!\n", str);
			}

			++cnt;

		}

		ASSERT_EQ(3, cnt);

	}
示例#2
0
文件: SSF.cpp 项目: Fluffiest/splayer
	bool CRenderer::Open(CString fn, CString name)
	{
		m_fn.Empty();
		m_name.Empty();
		m_file.Free();
		m_renderer.Free();

		if(name.IsEmpty())
		{
			CString str = fn;
			str.Replace('\\', '/');
			name = str.Left(str.ReverseFind('.'));
			name = name.Mid(name.ReverseFind('/')+1);
			name = name.Mid(name.ReverseFind('.')+1);
		}

		try
		{
			if(Open(FileInputStream(fn), name)) 
			{
				m_fn = fn;
				return true;
			}
		}
		catch(Exception& e)
		{
			UNREFERENCED_PARAMETER(e);
			TRACE(_T("%s\n"), e.ToString());
		}

		return false;	
	}
示例#3
0
FileEntitySchemeInputStream::FileEntitySchemeInputStream(ptr<Entity> entity)
: entity(entity), currentBlockIndex(0), currentBlockOffset(0), ended(false)
{
	BEGIN_TRY();

	// read descriptor
	ptr<File> descriptorFile = entity->ReadData(nullptr);
	if(!descriptorFile)
		THROW("No descriptor");

	descriptorReader = NEW(StreamReader(NEW(FileInputStream(descriptorFile))));

	// read & check the version
	size_t version = descriptorReader->ReadShortly();
	// for now only version 1 is supported
	if(version != 1)
		THROW("Invalid descriptor version");
	totalSize = descriptorReader->ReadShortlyBig();
	remainingSize = totalSize;

	hashStream = NEW(Crypto::WhirlpoolStream());
	totalHashStream = NEW(Crypto::WhirlpoolStream());

	// read total hash
	totalHashFromDescriptor = descriptorReader->Read(totalHashStream->GetHashSize());

	END_TRY("Can't create input stream for file entity");
}
示例#4
0
wxInt32 ExtractCompressedFile(const wxString &Filename, const wxString &SaveLocation)
{
    wxFileInputStream FileInputStream(Filename);

    if (!FileInputStream.IsOk())
        return 0;

    // Zip file handling
    // TODO: Complete this
    /*
    wxZipInputStream ZipInputStream(InputStream);

    if (ZipInputStream.IsOk())
    {
        while (ZipEntry.reset(ZipInputStream.GetNextEntry()), ZipEntry.get() != NULL)
        {
            // access meta-data
            wxString Name = ZipEntry->GetName();
            // read 'zip' to access the entry's data
            ZipInputStream.
        }
    }*/

    // Some older versions of zlib can't open gzip's
    /*
    if (wxZlibInputStream::CanHandleGZip())
    {
        wxZlibInputStream ZlibInputStream(FileInputStream);
    }*/
}
示例#5
0
// protected
void 
FileInputStreamTestCase::ctors (void)
{	
	FileInputStream fin (TEST_FILE_NAME);
	
	File file (TEST_FILE_NAME);
	
	FileInputStream fin2(TEST_FILE_NAME, READ_SHARE);
	CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, WRITE_SHARE), Exception);
	fin2.close ();
	fin.close ();
	
	FileInputStream fin3(TEST_FILE_NAME, NONE_SHARE);
	CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, READ_SHARE), Exception);
	
}
示例#6
0
ptr<InputStream> FileSystem::LoadStream(const String& fileName)
{
	try
	{
		return NEW(FileInputStream(LoadFile(fileName)));
	}
	catch(Exception* exception)
	{
		THROW_SECONDARY("Can't load file " + fileName + " as stream", exception);
	}
}
示例#7
0
BlobFileSystem::BlobFileSystem(ptr<File> file) : file(file)
{
	try
	{
		void* fileData = file->GetData();
		size_t fileSize = file->GetSize();
		size_t size = fileSize;

		//получить терминатор
		if(size < sizeof(Terminator))
			THROW("Can't read terminator");
		Terminator* terminator = (Terminator*)((char*)fileData + fileSize) - 1;
		size -= sizeof(*terminator);

		//проверить сигнатуру
		if(memcmp(terminator->magic, Terminator::magicValue, sizeof(terminator->magic)) != 0)
			THROW("Invalid magic");

		//проверить, что заголовок читается
		if(size < terminator->headerSize)
			THROW("Can't read header");

		//получить читатель заголовка
		ptr<StreamReader> headerReader = NEW(StreamReader(NEW(FileInputStream(
			NEW(PartFile(file, (char*)terminator - terminator->headerSize, terminator->headerSize))))));
		size -= terminator->headerSize;

		//считывать файлы, пока есть
		for(;;)
		{
			//считать имя файла
			String fileName = headerReader->ReadString();
			//если оно пустое, значит, это конец
			if(fileName.empty())
				break;

			//считать смещение до файла и его размер
			size_t fileOffset = headerReader->ReadShortly();
			size_t fileSize = headerReader->ReadShortly();

			//проверить, что файл читается
			if(fileOffset > size || size - fileOffset < fileSize)
				THROW("Can't read file " + fileName);
			
			//добавить файл в карту
			files[fileName] = NEW(PartFile(file, (char*)fileData + fileOffset, fileSize));
		}
	}
	catch(Exception* exception)
	{
		THROW_SECONDARY("Can't load blob file system", exception);
	}
}
示例#8
0
	TEST(Tar, open) {

		File folder = File(__FILE__).getParent();
		File file = File(folder, "test.tar");

		FileInputStream fis = FileInputStream(file);
		UnTarStream tar(&fis);

		unsigned int cnt = 0;
		while (tar.hasNext()) {
			tar.next();
			++cnt;
		}

		ASSERT_EQ(3, cnt);

	}
示例#9
0
	InputStreamPtr Directory::OpenRead(const String& path, const String& filename) {
		String fullpath = URL::GetAppendedPath(path, filename);
		std::FILE* file = 0;
#if NEX_LINUX == 1
		file = std::fopen(fullpath.c_str(), "rb");
#elif NEX_WINDOWS == 1
		FOPEN_W(file, StringUtils::ToUtf16(fullpath).c_str(), L"rb");
#else
#error no standard way to open files?
#endif
		if (!file) {
			return InputStreamPtr();
		}
		FileInputStream* ptr =
			NEX_NEW(
			FileInputStream(file, static_cast<uint32>(Constants::INVALID_SIZE)));
		return Assign<InputStream>(ptr);
	}