9FileBuffer::FileBuffer(FileHandleRef fh) {
14FileBuffer::~FileBuffer() {
17void FileBuffer::rewindToStart() {
22bool FileBuffer::available()
const {
23 if (mCurrIdx != mLength) {
31 return mFile->available();
34int32_t FileBuffer::BytesLeft()
const {
38 const int32_t remaining_buffer = mLength - mCurrIdx;
39 const int32_t remaining_disk = mFile->size() - mFile->pos();
40 return remaining_buffer + remaining_disk;
43int32_t FileBuffer::FileSize()
const {
50int16_t FileBuffer::read() {
51 RefillBufferIfNecessary();
52 if (mCurrIdx == mLength) {
56 uint8_t output = mBuffer[mCurrIdx++];
60size_t FileBuffer::read(uint8_t* dst,
size_t n) {
61 size_t bytes_read = 0;
62 for (
size_t i = 0; i < n; i++) {
63 int16_t next_byte = read();
64 if (next_byte == -1) {
67 dst[bytes_read++] =
static_cast<uint8_t
>(next_byte);
72void FileBuffer::ResetBuffer() {
77void FileBuffer::RefillBufferIfNecessary() {
78 if (mCurrIdx == mLength) {
83void FileBuffer::RefillBuffer() {
84 if (!mFile->available()) {
88 mLength = mFile->read(mBuffer, kBufferSize);