Permalink
Browse files

Kill off more unused code in RIFFReader

  • Loading branch information...
hrydgard committed Dec 4, 2017
1 parent 1c0a0fe commit 210b70ff0c8ae4f5fefe68c8232a854faa0cecb3
Showing with 3 additions and 66 deletions.
  1. +3 −59 ext/native/file/chunk_file.cpp
  2. +0 −7 ext/native/file/chunk_file.h
@@ -9,65 +9,23 @@ inline uint32_t flipID(uint32_t id) {
return ((id >> 24) & 0xFF) | ((id >> 8) & 0xFF00) | ((id << 8) & 0xFF0000) | ((id << 24) & 0xFF000000);
}
RIFFReader::RIFFReader(const char *filename) {
data_ = 0;
filename_ = filename;
depth_ = 0;
pos_ = 0;
didFail_ = false;
fastMode = true;
if (fastMode) {
size_t size;
data_ = (uint8_t *)VFSReadFile(filename, &size);
if (!data_) {
ELOG("Chunkfile fail: %s", filename);
didFail_ = true;
return;
}
eof_ = (int)size;
return;
}
file = openCFile(filename, "wb");
if (file) {
didFail_ = false;
eof_ = 0;
} else {
didFail_ = true;
}
}
RIFFReader::RIFFReader(const uint8_t *data, int dataSize) {
data_ = new uint8_t[dataSize];
memcpy(data_, data, dataSize);
fastMode = true;
depth_ = 0;
pos_ = 0;
didFail_ = false;
eof_ = dataSize;
}
RIFFReader::~RIFFReader() {
if (fastMode) {
delete[] data_;
} else {
fclose(file);
}
delete[] data_;
}
int RIFFReader::readInt() {
if (data_ && pos_ < eof_) {
pos_ += 4;
if (fastMode)
return *(int *)(data_ + pos_ - 4);
else {
int i;
if (fread(&i, 1, 4, file) == 4) {
return i;
}
}
return *(int *)(data_ + pos_ - 4);
}
return 0;
}
@@ -123,9 +81,6 @@ bool RIFFReader::descend(uint32_t id) {
}
void RIFFReader::seekTo(int _pos) {
if (!fastMode) {
fseek(file, 0, SEEK_SET);
}
pos_ = _pos;
}
@@ -143,23 +98,12 @@ void RIFFReader::ascend() {
// read a block
void RIFFReader::readData(void *what, int count) {
if (fastMode) {
memcpy(what, data_ + pos_, count);
} else {
if (fread(what, 1, count, file) != (size_t)count) {
ELOG("Failed to read complete %d bytes", count);
}
}
memcpy(what, data_ + pos_, count);
pos_ += count;
count &= 3;
if (count) {
count = 4 - count;
if (!fastMode) {
if (fseek(file, count, SEEK_CUR) != 0) {
ELOG("Missing padding");
}
}
pos_ += count;
}
}
@@ -16,9 +16,7 @@
class RIFFReader {
public:
RIFFReader(const char *filename);
RIFFReader(const uint8_t *data, int dataSize);
~RIFFReader();
bool descend(uint32_t id);
@@ -32,7 +30,6 @@ class RIFFReader {
int getCurrentChunkSize();
bool failed() const { return didFail_; }
std::string filename() const { return filename_; }
private:
struct ChunkInfo {
@@ -48,12 +45,8 @@ class RIFFReader {
uint8_t *data_;
int pos_ = 0;
int eof_ = 0;
bool fastMode;
bool didFail_ = false;
std::string filename_;
FILE *file = nullptr;
void seekTo(int _pos);
int getPos() const {return pos_;}
};

0 comments on commit 210b70f

Please sign in to comment.