Skip to content

Latest commit

 

History

History
119 lines (96 loc) · 3.69 KB

fileio.h

File metadata and controls

119 lines (96 loc) · 3.69 KB
 
May 12, 2007
May 12, 2007
1
2
3
4
5
6
7
8
/**
* MojoSetup; a portable, flexible installation application.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
Mar 23, 2006
Mar 23, 2006
9
10
11
12
13
#ifndef _INCL_FILEIO_H_
#define _INCL_FILEIO_H_
#include "universal.h"
Mar 24, 2006
Mar 24, 2006
14
15
16
17
#ifdef __cplusplus
extern "C" {
#endif
Mar 23, 2006
Mar 23, 2006
18
19
20
21
22
23
24
/*
* 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,
Dec 2, 2006
Dec 2, 2006
25
* done transparently and with arbitrary depth, although usually not more
Mar 23, 2006
Mar 23, 2006
26
27
28
29
* than one deep. This also works as a general transport layer, so the
* abstraction could be extended to network connections and such, too.
*/
Mar 25, 2006
Mar 25, 2006
30
// Abstract input interface. Files, memory, archive entries, etc.
Mar 23, 2006
Mar 23, 2006
31
32
33
typedef struct MojoInput MojoInput;
struct MojoInput
{
Mar 25, 2006
Mar 25, 2006
34
// public
May 7, 2007
May 7, 2007
35
boolean (*ready)(MojoInput *io);
Mar 26, 2006
Mar 26, 2006
36
int64 (*read)(MojoInput *io, void *buf, uint32 bufsize);
Mar 23, 2006
Mar 23, 2006
37
boolean (*seek)(MojoInput *io, uint64 pos);
Mar 26, 2006
Mar 26, 2006
38
39
40
int64 (*tell)(MojoInput *io);
int64 (*length)(MojoInput *io);
MojoInput* (*duplicate)(MojoInput *io);
Mar 23, 2006
Mar 23, 2006
41
42
void (*close)(MojoInput *io);
Mar 25, 2006
Mar 25, 2006
43
// private
Mar 23, 2006
Mar 23, 2006
44
45
46
void *opaque;
};
Jan 13, 2008
Jan 13, 2008
47
48
// This copies the memory, so you may free (ptr) after this function returns.
MojoInput *MojoInput_newFromMemory(const uint8 *ptr, uint32 len, int constant);
Mar 23, 2006
Mar 23, 2006
49
50
MojoInput *MojoInput_newFromFile(const char *fname);
Jan 13, 2008
Jan 13, 2008
51
Mar 25, 2006
Mar 25, 2006
52
53
typedef enum
{
Mar 25, 2006
Mar 25, 2006
54
55
MOJOARCHIVE_ENTRY_UNKNOWN = 0,
MOJOARCHIVE_ENTRY_FILE,
Mar 25, 2006
Mar 25, 2006
56
57
58
MOJOARCHIVE_ENTRY_DIR,
MOJOARCHIVE_ENTRY_SYMLINK,
} MojoArchiveEntryType;
Mar 23, 2006
Mar 23, 2006
59
Mar 25, 2006
Mar 25, 2006
60
// Abstract archive interface. Archives, directories, etc.
Apr 29, 2007
Apr 29, 2007
61
typedef struct MojoArchiveEntry
Mar 23, 2006
Mar 23, 2006
62
{
Mar 25, 2006
Mar 25, 2006
63
char *filename;
May 1, 2007
May 1, 2007
64
char *linkdest;
Mar 23, 2006
Mar 23, 2006
65
MojoArchiveEntryType type;
Mar 25, 2006
Mar 25, 2006
66
int64 filesize;
May 3, 2007
May 3, 2007
67
uint16 perms;
Apr 29, 2007
Apr 29, 2007
68
} MojoArchiveEntry;
Mar 23, 2006
Mar 23, 2006
69
May 4, 2007
May 4, 2007
70
void MojoArchive_resetEntry(MojoArchiveEntry *info);
Mar 26, 2006
Mar 26, 2006
71
72
Mar 23, 2006
Mar 23, 2006
73
74
75
typedef struct MojoArchive MojoArchive;
struct MojoArchive
{
Mar 25, 2006
Mar 25, 2006
76
// public
May 4, 2007
May 4, 2007
77
boolean (*enumerate)(MojoArchive *ar);
Apr 29, 2007
Apr 29, 2007
78
const MojoArchiveEntry* (*enumNext)(MojoArchive *ar);
Mar 23, 2006
Mar 23, 2006
79
80
81
MojoInput* (*openCurrentEntry)(MojoArchive *ar);
void (*close)(MojoArchive *ar);
Mar 25, 2006
Mar 25, 2006
82
// private
Mar 23, 2006
Mar 23, 2006
83
MojoInput *io;
Apr 29, 2007
Apr 29, 2007
84
MojoArchiveEntry prevEnum;
Jan 16, 2008
Jan 16, 2008
85
int64 offsetOfStart; // byte offset in MojoInput where archive starts.
Mar 23, 2006
Mar 23, 2006
86
87
88
void *opaque;
};
Mar 24, 2006
Mar 24, 2006
89
MojoArchive *MojoArchive_newFromDirectory(const char *dirname);
May 5, 2007
May 5, 2007
90
MojoArchive *MojoArchive_newFromInput(MojoInput *io, const char *origfname);
Mar 23, 2006
Mar 23, 2006
91
Dec 3, 2006
Dec 3, 2006
92
93
94
95
96
97
98
// This will reset enumeration in the archive, don't use it while iterating!
// Also, this can be very slow depending on the archive in question, so
// try to limit your random access filename lookups to known-fast quantities
// (like directories on the physical filesystem or a zipfile...tarballs and
// zipfiles-in-zipfiles will bog down here, for example).
MojoInput *MojoInput_newFromArchivePath(MojoArchive *ar, const char *fname);
Mar 25, 2006
Mar 25, 2006
99
extern MojoArchive *GBaseArchive;
May 20, 2007
May 20, 2007
100
extern const char *GBaseArchivePath;
Mar 25, 2006
Mar 25, 2006
101
102
103
MojoArchive *MojoArchive_initBaseArchive(void);
void MojoArchive_deinitBaseArchive(void);
May 8, 2007
May 8, 2007
104
105
typedef boolean (*MojoInput_FileCopyCallback)(uint32 ticks, int64 justwrote,
int64 bw, int64 total, void *data);
May 3, 2007
May 3, 2007
106
boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname, uint16 perms,
Jan 16, 2008
Jan 16, 2008
107
MojoChecksums *checksums, int64 maxbytes,
May 1, 2007
May 1, 2007
108
MojoInput_FileCopyCallback cb, void *data);
Mar 25, 2006
Mar 25, 2006
109
Jan 17, 2008
Jan 17, 2008
110
MojoInput *MojoInput_newFromURL(const char *url);
May 5, 2007
May 5, 2007
111
Mar 24, 2006
Mar 24, 2006
112
113
114
115
#ifdef __cplusplus
}
#endif
Mar 23, 2006
Mar 23, 2006
116
117
#endif
Mar 25, 2006
Mar 25, 2006
118
// end of fileio.h ...