Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef _INCL_FILEIO_H_ | ||
#define _INCL_FILEIO_H_ | ||
|
||
#include "universal.h" | ||
|
||
/* | ||
* File i/o may go through multiple layers: the archive attached to the binary, | ||
* then an archive in there that's being read entirely out of memory that's | ||
* being uncompressed to on the fly, or it might be a straight read from a | ||
* regular uncompressed file on physical media. It might be a single file | ||
* compressed with bzip2. As such, we have to have an abstraction over the | ||
* usual channels...basically what we need here is archives-within-archives, | ||
* done transparently and with arbitrary depth (although usually not more | ||
* than one deep. This also works as a general transport layer, so the | ||
* abstraction could be extended to network connections and such, too. | ||
*/ | ||
|
||
/* Abstract input interface. Files, memory, archive entries, etc. */ | ||
typedef struct MojoInput MojoInput; | ||
struct MojoInput | ||
{ | ||
/*public*/ | ||
size_t (*read)(MojoInput *io, void *buf, size_t bufsize); | ||
boolean (*seek)(MojoInput *io, uint64 pos); | ||
uint64 (*tell)(MojoInput *io); | ||
void (*close)(MojoInput *io); | ||
|
||
/*private*/ | ||
void *opaque; | ||
}; | ||
|
||
MojoInput *MojoInput_newFromFile(const char *fname); | ||
MojoInput *MojoInput_newFromMemory(void *mem, size_t bytes); | ||
|
||
|
||
/* Abstract archive interface. Archives, directories, etc. */ | ||
typedef struct MojoArchiveEntryInfo MojoArchiveEntryInfo; | ||
struct MojoArchiveEntryInfo | ||
{ | ||
const char *filename; | ||
MojoArchiveEntryType type; | ||
sint64 filesize; | ||
}; | ||
|
||
typedef struct MojoArchive MojoArchive; | ||
struct MojoArchive | ||
{ | ||
/*public*/ | ||
void (*restartEnumeration)(MojoArchive *ar); | ||
const MojoArchiveEntryInfo* (*enumEntry)(MojoArchive *ar); | ||
MojoInput* (*openCurrentEntry)(MojoArchive *ar); | ||
void (*close)(MojoArchive *ar); | ||
|
||
/*private*/ | ||
MojoInput *io; | ||
MojoArchiveEntryInfo lastEnumInfo; | ||
void *opaque; | ||
}; | ||
|
||
MojoArchive *MojoArchive_newFromInput(MojoInput *io, const char *origfname); | ||
|
||
#endif | ||
|
||
/* end of fileio.h ... */ | ||
|