wavelength 1.0.0
Loading...
Searching...
No Matches
lazyfilestream.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5#include "os/file.h"
6#include "os/string.h"
7
15public:
24 LazyFileStream(const String &filename, int nBufferSize);
25
33
41 bool Eof() const;
42
50 bool ReadDone();
51
61 char *GetData(int *pnPosition, int *pnBytesAvailable);
62
63private:
65 static constexpr unsigned int kNumBuffers = 2;
66
73 void StartRead();
74
75 int mMoreData;
76 int mPosition;
77 std::unique_ptr<File> mFile;
78 char *mBuffers[kNumBuffers];
79 unsigned int mCurBuffer;
80 int mBufferSize;
81 int mBytesAvailable;
82};
LazyFileStream(const String &filename, int nBufferSize)
Open a file, allocate the buffers, and start the first read.
char * GetData(int *pnPosition, int *pnBytesAvailable)
Take the buffer of the completed read, and start the next read unless the file ended.
bool ReadDone()
Report whether the read in flight is complete, recording how many bytes arrived.
~LazyFileStream()
Close the file and free the buffers.
bool Eof() const
Report whether the last read reached the end of the file.
Growable text buffer that is also a PrnStream.
Definition string.h:19