MCPcopy Create free account
hub / github.com/FFMS/ffms2 / Read

Method Read

src/core/zipfile.cpp:58–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58void ZipFile::Read(void *data, size_t size) {
59 if (state == Deflate) {
60 deflateEnd(&z);
61 state = Initial;
62 }
63 if (state != Inflate) {
64 if (inflateInit(&z) != Z_OK)
65 throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, "Failed to initialize zlib");
66 state = Inflate;
67 }
68
69 z.next_out = static_cast<unsigned char *>(data);
70 z.avail_out = size;
71 if (!z.avail_in && !is_file) {
72 z.next_in = reinterpret_cast<Bytef*>(&index_buffer[0]);
73 z.avail_in = index_buffer.size();
74 }
75 do {
76 if (!z.avail_in && is_file) {
77 z.next_in = reinterpret_cast<Bytef*>(&buffer[0]);
78 z.avail_in = file.Read(&buffer[0], buffer.size());
79 }
80 if (!z.avail_in) {
81 if (!is_file)
82 throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, "Failed to read data: Buffer is empty");
83 else if (!file.Tell())
84 throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, "Failed to read data: File is empty");
85 }
86
87 switch (inflate(&z, Z_SYNC_FLUSH)) {
88 case Z_NEED_DICT:
89 throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, "Failed to read data: Dictionary error.");
90 case Z_DATA_ERROR:
91 throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, "Failed to read data: Data error.");
92 case Z_MEM_ERROR:
93 throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, "Failed to read data: Memory error.");
94 case Z_STREAM_END:
95 if (z.avail_out > 0)
96 throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, "Failed to read data: Stream ended early");
97 }
98 } while (z.avail_out);
99}
100
101int ZipFile::Write(const void *data, size_t size) {
102 if (state == Inflate) {

Callers 2

ReadIndexMethod · 0.45

Calls 3

FFMS_ExceptionClass · 0.85
sizeMethod · 0.80
TellMethod · 0.80

Tested by

no test coverage detected