wavelength 1.0.0
Loading...
Searching...
No Matches
asyncfile.h
Go to the documentation of this file.
1#pragma once
2
3#include "os/file.h"
4#include "os/string.h"
5
13class AsyncFile : public File {
14public:
23 AsyncFile(const char *pszFile, int nMode);
24
31 ~AsyncFile() override;
32
39 static void Init();
40
49 static void Terminate();
50
60 int Read(void *pBuffer, int nBytes) override;
61
71 bool ReadAsync(void *pBuffer, int nBytes) override;
72
82 int Write(const void *pBuffer, int nBytes) override;
83
93 int Seek(int nOffset, int nOrigin) override;
94
102 int Tell() override {
103 return mTell;
104 }
105
113 void Flush() override;
114
122 bool Eof() override {
123 return mTell == mSize;
124 }
125
133 bool Fail() override {
134 return mFail != 0;
135 }
136
144 int Size() override {
145 return mSize;
146 }
147
155 int UncompressedSize() override {
156 return mUncompressedSize;
157 }
158
167 bool ReadDone(int *pnBytes) override;
168
177 void Open(const char *pszFile, int nMode);
178
185 void Close();
186
187private:
195 static void FreeDescriptor();
196
204 int OpenDescriptor();
205
215 int WriteDescriptor(const void *pBuffer, int nBytes);
216
223 void SeekDescriptor();
224
233 void ReadDescriptor(void *pBuffer, int nBytes);
234
242 bool DescriptorDone();
243
250 void CloseDescriptor();
251
252 int mMode;
253 int mFd;
254 int mSize;
255 int mUncompressedSize;
256 int mTell;
257 int mBufferOffset;
258 int mReadStarted;
259 int mFail;
260 char *mBuffer;
261 char *mReadDest;
262 int mReadRemaining;
263 int mReadDone;
264 String mFilename;
265};
int Seek(int nOffset, int nOrigin) override
Move the position, clamped to the file, and refill the buffer of a file opened to read.
AsyncFile(const char *pszFile, int nMode)
Allocate the buffer and open a file.
static void Init()
Read the buf_size setting of the file block of the system configuration.
bool ReadAsync(void *pBuffer, int nBytes) override
Start reading bytes.
int Write(const void *pBuffer, int nBytes) override
Write bytes into the buffer, writing out each full buffer.
~AsyncFile() override
Close the file and release the buffer.
int Tell() override
Report the position.
Definition asyncfile.h:102
bool Fail() override
Report whether an operation failed.
Definition asyncfile.h:133
int UncompressedSize() override
Report the size before compression.
Definition asyncfile.h:155
void Open(const char *pszFile, int nMode)
Open a file, and read the size before compression of a .gz file opened to read.
int Size() override
Report the size.
Definition asyncfile.h:144
bool ReadDone(int *pnBytes) override
Copy what the buffer has of the read, refilling the buffer when the read needs more.
void Flush() override
Write out the buffer of a file opened to write, or start refilling the buffer of a file opened to rea...
int Read(void *pBuffer, int nBytes) override
Read bytes and wait for them.
void Close()
Write out the buffer of a file opened to write, close the file, and reset the state.
bool Eof() override
Report whether the position is at the end.
Definition asyncfile.h:122
static void Terminate()
Shut the file layer down.
Open file of the host or the disc.
Definition file.h:29
Growable text buffer that is also a PrnStream.
Definition string.h:19