wavelength 1.0.0
Loading...
Searching...
No Matches
ChunkStream Class Reference

BinStream over a file stored as a header and a run of blocks, each optionally deflated. More...

#include <chunkstream.h>

Inheritance diagram for ChunkStream:
Collaboration diagram for ChunkStream:

Classes

struct  Header
 The header at the start of the file. More...

Public Types

enum  Mode { kModeRead = 0 , kModeWrite = 1 }
 Directions a stream opens in. More...
Public Types inherited from BinStream
enum  SeekType {
  kSeekBegin = 0 , kSeekCurrent = 1 , kSeekEnd = 2 , kSeekBegin = 0 ,
  kSeekCurrent = 1 , kSeekEnd = 2
}
 Origins of Seek(). More...
enum  SeekType {
  kSeekBegin = 0 , kSeekCurrent = 1 , kSeekEnd = 2 , kSeekBegin = 0 ,
  kSeekCurrent = 1 , kSeekEnd = 2
}
 The origin of Seek(). More...

Public Member Functions

 ChunkStream (const char *pszFile, Mode eMode, int nChunkSize, bool bCompressed, bool bLittleEndian)
 Open a file and start reading its header, or write a fresh header.
 ~ChunkStream () override
 Write the last block and the final header of a writer, and close the file.
void Read (void *pData, int nBytes) override
 Copy bytes out of the current block.
void Write (const void *pData, int nBytes) override
 Append bytes to the block being gathered.
void Flush () override
 Do nothing.
void Seek (int nOffset, SeekType eFrom) override
 Report that the stream cannot seek.
int Tell () override
 Report that the stream cannot report a position.
bool Eof () override
 Advance the background reads, and report whether the current block is still unavailable.
bool Fail () override
 Report whether the file failed to open or a block failed to write.
void Mark (const char *pszMark) override
 End the block at a mark of g_szChunkMark once it has reached the chunk size.
Public Member Functions inherited from BinStream
 BinStream (bool bLittleEndian)
 Construct a stream.
virtual ~BinStream ()
 Release the stream.
void ReadString (char *pszBuffer, int nSize)
 Read a length-prefixed string into a buffer and terminate it.
void ReadString (String &text)
 Read a length-prefixed string.
BinStream & WriteString (const char *pszText)
 Write a string with its length first.
void ReadEndian (void *pData, int nBytes)
 Read a value of 2, 4, 8, or 16 bytes, reversing its bytes unless the stream is little endian.
void WriteEndian (const void *pData, int nBytes)
 Write a value of 2, 4, 8, or 16 bytes, reversing its bytes unless the stream is little endian.
 BinStream (bool littleEndian)
 Set the byte order.
virtual ~BinStream ()
 Destroy the stream.
virtual void NoOp (int)
 Do nothing.
void ReadEndian (void *data, int bytes)
 Read a value, swapping its bytes into the host order.
void WriteEndian (const void *data, int bytes)
 Write a value, swapping its bytes into the stream order.
BinStream & operator<< (const char *str)
 Write text as its length followed by its characters, without a terminator.
BinStream & operator>> (String &str)
 Read text written by operator<<(const char *).
void ReadString (char *buffer, int bufSize)
 Read text written by operator<<(const char *) into a buffer, and terminate it.
BinStream & operator<< (char c)
BinStream & operator<< (unsigned char c)
BinStream & operator<< (short s)
BinStream & operator<< (unsigned short s)
BinStream & operator<< (int i)
BinStream & operator<< (unsigned int i)
BinStream & operator<< (float f)
BinStream & operator>> (char &c)
BinStream & operator>> (unsigned char &c)
BinStream & operator>> (short &s)
BinStream & operator>> (unsigned short &s)
BinStream & operator>> (int &i)
BinStream & operator>> (unsigned int &i)
BinStream & operator>> (float &f)

Static Public Attributes

static constexpr int kMaxBlocks = 50
 Blocks the header describes at most.
static constexpr unsigned int kMagicCompressed = 0xccbedeaf
 mMagic of a file with deflated blocks.
static constexpr unsigned int kMagicPlain = 0xcabedeaf
 mMagic of a file with plain blocks.

Detailed Description

BinStream over a file stored as a header and a run of blocks, each optionally deflated.

The RTTI includes the class name and records BinStream as the base. A reader reads the header and the blocks in the background, two block buffers in turn. A writer gathers a block in memory until the block reaches the chunk size at a mark of g_szChunkMark, and rewrites the header when the stream is deleted.

Member Enumeration Documentation

◆ Mode

Directions a stream opens in.

Enumerator
kModeRead 

Read the file.

kModeWrite 

Create or replace the file.

Constructor & Destructor Documentation

◆ ChunkStream()

ChunkStream::ChunkStream ( const char * pszFile,
Mode eMode,
int nChunkSize,
bool bCompressed,
bool bLittleEndian )

Open a file and start reading its header, or write a fresh header.

Parameters
pszFileThe file.
eModeThe direction.
nChunkSizeThe size at which a writer ends a block at a mark.
bCompressedWhether a writer deflates the blocks.
bLittleEndianWhether values are stored in the console's byte order.
Ghidra address:
NTSC-U/C: 0x002952a0
Ghidra address:
PAL: 0x0029eec8

◆ ~ChunkStream()

ChunkStream::~ChunkStream ( )
override

Write the last block and the final header of a writer, and close the file.

Ghidra address:
NTSC-U/C: 0x002953f8
Ghidra address:
PAL: 0x0029f020

Member Function Documentation

◆ Read()

void ChunkStream::Read ( void * pData,
int nBytes )
overridevirtual

Copy bytes out of the current block.

The caller first waits for the block through Eof(). The bounds are not checked.

Parameters
pDataThe destination.
nBytesThe number of bytes.
Ghidra address:
NTSC-U/C: 0x002954e8
Ghidra address:
PAL: 0x0029f100

Implements BinStream.

◆ Write()

void ChunkStream::Write ( const void * pData,
int nBytes )
overridevirtual

Append bytes to the block being gathered.

Parameters
pDataThe source.
nBytesThe number of bytes.
Ghidra address:
NTSC-U/C: 0x00295538
Ghidra address:
PAL: 0x0029f150

Implements BinStream.

◆ Flush()

void ChunkStream::Flush ( )
inlineoverridevirtual

Do nothing.

Ghidra address:
NTSC-U/C: 0x002955f0
Ghidra address:
PAL: 0x0029f208

Implements BinStream.

◆ Seek()

void ChunkStream::Seek ( int nOffset,
SeekType eFrom )
overridevirtual

Report that the stream cannot seek.

Parameters
nOffsetNot used.
eFromNot used.
Ghidra address:
NTSC-U/C: 0x002955f8
Ghidra address:
PAL: 0x0029f210

Implements BinStream.

◆ Tell()

int ChunkStream::Tell ( )
overridevirtual

Report that the stream cannot report a position.

Returns
0.
Ghidra address:
NTSC-U/C: 0x00295618
Ghidra address:
PAL: 0x0029f230

Implements BinStream.

◆ Eof()

bool ChunkStream::Eof ( )
overridevirtual

Advance the background reads, and report whether the current block is still unavailable.

Returns
Whether no byte of a new block is ready yet.
Ghidra address:
NTSC-U/C: 0x00295640
Ghidra address:
PAL: 0x0029f258

Implements BinStream.

◆ Fail()

bool ChunkStream::Fail ( )
overridevirtual

Report whether the file failed to open or a block failed to write.

Returns
mFail.
Ghidra address:
NTSC-U/C: 0x00295960
Ghidra address:
PAL: 0x0029f578

Implements BinStream.

◆ Mark()

void ChunkStream::Mark ( const char * pszMark)
overridevirtual

End the block at a mark of g_szChunkMark once it has reached the chunk size.

Parameters
pszMarkThe mark.
Ghidra address:
NTSC-U/C: 0x00295968
Ghidra address:
PAL: 0x0029f580

Reimplemented from BinStream.

Member Data Documentation

◆ kMaxBlocks

int ChunkStream::kMaxBlocks = 50
staticconstexpr

Blocks the header describes at most.

◆ kMagicCompressed

unsigned int ChunkStream::kMagicCompressed = 0xccbedeaf
staticconstexpr

mMagic of a file with deflated blocks.

◆ kMagicPlain

unsigned int ChunkStream::kMagicPlain = 0xcabedeaf
staticconstexpr

mMagic of a file with plain blocks.


The documentation for this class was generated from the following file: