------------------------------------------------------------------------------
| 76 | |
| 77 | //------------------------------------------------------------------------------ |
| 78 | bool FileStreamReader::open(const char* fileName) |
| 79 | { |
| 80 | if (!this->Open) |
| 81 | { |
| 82 | this->FileName = std::string(fileName); |
| 83 | // zlib handles both compressed and uncompressed file |
| 84 | // we just have peak into the file and see if it has the magic |
| 85 | // flags or not |
| 86 | unsigned char magic[2]; |
| 87 | FILE* ff = vtksys::SystemTools::Fopen(fileName, "rb"); |
| 88 | size_t count = fread(magic, 1, 2, ff); |
| 89 | fclose(ff); |
| 90 | |
| 91 | // only continue if fread succeeded |
| 92 | if (count == 2) |
| 93 | { |
| 94 | const char* mode = (magic[0] == 0x1f && magic[1] == 0x8b) ? "rb" : "r"; |
| 95 | #if defined(_WIN32) |
| 96 | std::wstring fileNameWide = vtksys::Encoding::ToWide(fileName); |
| 97 | this->file = gzopen_w(fileNameWide.c_str(), mode); |
| 98 | #else |
| 99 | this->file = gzopen(fileName, mode); |
| 100 | #endif |
| 101 | |
| 102 | this->Eof = (this->file == nullptr); |
| 103 | this->Open = (this->file != nullptr); |
| 104 | this->Pos = BUFF_SIZE; |
| 105 | } |
| 106 | } |
| 107 | return this->Open; |
| 108 | } |
| 109 | //------------------------------------------------------------------------------ |
| 110 | int FileStreamReader::get() |
| 111 | { |
no test coverage detected