Initial base for string pools, which are reference counted; Have closeable variant...
[SquirrelJME.git] / nanocoat / include / sjme / zip.h
blob135aa26074e56497f52ca2282fc2dbd6fcfb5f43
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 /**
11 * Zip Support.
13 * @since 2023/12/31
16 #ifndef SQUIRRELJME_ZIP_H
17 #define SQUIRRELJME_ZIP_H
19 #include "sjme/stream.h"
20 #include "sjme/seekable.h"
21 #include "sjme/path.h"
23 /* Anti-C++. */
24 #ifdef __cplusplus
25 #ifndef SJME_CXX_IS_EXTERNED
26 #define SJME_CXX_IS_EXTERNED
27 #define SJME_CXX_SQUIRRELJME_ZIP_H
28 extern "C" {
29 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
30 #endif /* #ifdef __cplusplus */
32 /*--------------------------------------------------------------------------*/
34 /**
35 * Opaque Zip structure.
37 * @since 2023/12/31
39 typedef struct sjme_zipBase* sjme_zip;
41 /**
42 * Zip access information.
44 * @since 2023/12/31
46 typedef struct sjme_zipBase
48 /** The closeable for this Zip. */
49 sjme_closeableBase closeable;
51 /** The pool this was allocated within. */
52 sjme_alloc_pool* inPool;
54 /** The central directory position. */
55 sjme_jint centralDirPos;
57 /** The logical start position of the central directory. */
58 sjme_jint logicalCentralDirPos;
60 /** The end central directory record position. */
61 sjme_jint endCentralDirPos;
63 /** The start position of the Zip in the seekable. */
64 sjme_jint archiveStartPos;
66 /** The seekable where the Zip is. */
67 sjme_seekable seekable;
69 /** The lock for accessing the Zip. */
70 sjme_thread_spinLock lock;
71 } sjme_zipBase;
73 /**
74 * Zip entry.
76 * @since 2023/12/31
78 typedef struct sjme_zip_entry
80 /** The Zip this is in. */
81 sjme_zip zip;
83 /** The version this was made by. */
84 sjme_jchar versionMadeBy;
86 /** The version needed to extract. */
87 sjme_jchar versionNeeded;
89 /** General purpose bits. */
90 sjme_jchar generalBits;
92 /** Compression method. */
93 sjme_jchar method;
95 /** Last modification time. */
96 sjme_jchar lastModTime;
98 /** Last modification date. */
99 sjme_jchar lastModDate;
101 /** Uncompressed CRC. */
102 sjme_jint uncompressedCrc;
104 /** Compressed size. */
105 sjme_jint compressedSize;
107 /** Uncompressed size. */
108 sjme_jint uncompressedSize;
110 /** Disk number. */
111 sjme_jchar diskNum;
113 /** Internal attributes. */
114 sjme_jchar internalAttrib;
116 /** External attributes. */
117 sjme_jint externalAttrib;
119 /** Relative offset to the local file header. */
120 sjme_jint offset;
122 /** The file name. */
123 sjme_cchar name[SJME_MAX_FILE_NAME];
124 } sjme_zip_entry;
127 * Opens a stream to read the given Zip entry.
129 * @param inEntry The entry to read from.
130 * @param outStream The resultant stream for reading the data.
131 * @return On any error, if any.
132 * @since 2023/12/31
134 sjme_errorCode sjme_zip_entryRead(
135 sjme_attrInNotNull const sjme_zip_entry* inEntry,
136 sjme_attrOutNotNull sjme_stream_input* outStream);
139 * Locates an entry within a Zip file.
141 * @param inZip The Zip to look within.
142 * @param outEntry The resultant entry.
143 * @param entryName The entry to look for.
144 * @return On any error, if any.
145 * @since 2023/12/31
147 sjme_errorCode sjme_zip_locateEntry(
148 sjme_attrInNotNull sjme_zip inZip,
149 sjme_attrOutNotNull sjme_zip_entry* outEntry,
150 sjme_attrInNotNull sjme_lpcstr entryName);
153 * Opens a Zip file at the given location.
155 * @param inPool The pool for structure allocation.
156 * @param outZip The resultant opened Zip file.
157 * @param rawData Raw data to the Zip in memory somewhere.
158 * @param rawSize The length of the Zip data.
159 * @return Any resultant error code, if any.
160 * @since 2023/12/31
162 sjme_errorCode sjme_zip_openMemory(
163 sjme_attrInNotNull sjme_alloc_pool* inPool,
164 sjme_attrOutNotNull sjme_zip* outZip,
165 sjme_attrInNotNull void* rawData,
166 sjme_attrInPositive sjme_jint rawSize);
169 * Opens a Zip from the given seekable.
171 * @param inPool The pool to allocate from.
172 * @param outZip The resultant opened Zip.
173 * @param inSeekable The seekable to use for accessing data.
174 * @return Any resultant error, if any.
175 * @since 2024/08/12
177 sjme_errorCode sjme_zip_openSeekable(
178 sjme_attrInNotNull sjme_alloc_pool* inPool,
179 sjme_attrOutNotNull sjme_zip* outZip,
180 sjme_attrInNotNull sjme_seekable inSeekable);
182 /*--------------------------------------------------------------------------*/
184 /* Anti-C++. */
185 #ifdef __cplusplus
186 #ifdef SJME_CXX_SQUIRRELJME_ZIP_H
188 #undef SJME_CXX_SQUIRRELJME_ZIP_H
189 #undef SJME_CXX_IS_EXTERNED
190 #endif /* #ifdef SJME_CXX_SQUIRRELJME_ZIP_H */
191 #endif /* #ifdef __cplusplus */
193 #endif /* SQUIRRELJME_ZIP_H */