Merge pull request #25959 from neo1973/TagLib_deprecation_warnings
[xbmc.git] / lib / libUPnP / Neptune / Source / Core / NptZip.h
blobfbbebcb263cdda9d00270c1e949934c08ced2380
1 /*****************************************************************
3 | Neptune - Zip Support
5 | Copyright (c) 2002-2008, Axiomatic Systems, LLC.
6 | All rights reserved.
8 | Redistribution and use in source and binary forms, with or without
9 | modification, are permitted provided that the following conditions are met:
10 | * Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 | * Redistributions in binary form must reproduce the above copyright
13 | notice, this list of conditions and the following disclaimer in the
14 | documentation and/or other materials provided with the distribution.
15 | * Neither the name of Axiomatic Systems nor the
16 | names of its contributors may be used to endorse or promote products
17 | derived from this software without specific prior written permission.
19 | THIS SOFTWARE IS PROVIDED BY AXIOMATIC SYSTEMS ''AS IS'' AND ANY
20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL AXIOMATIC SYSTEMS BE LIABLE FOR ANY
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ****************************************************************/
32 #ifndef _NPT_ZIP_H_
33 #define _NPT_ZIP_H_
35 /*----------------------------------------------------------------------
36 | includes
37 +---------------------------------------------------------------------*/
38 #include "NptConfig.h"
39 #include "NptStreams.h"
40 #include "NptArray.h"
41 #include "NptFile.h"
43 /*----------------------------------------------------------------------
44 | class references
45 +---------------------------------------------------------------------*/
46 class NPT_ZipInflateState;
47 class NPT_ZipDeflateState;
49 /*----------------------------------------------------------------------
50 | NPT_ZipFile
51 +---------------------------------------------------------------------*/
52 const unsigned int NPT_ZIP_FILE_FLAG_ENCRYPTED = 0x01;
53 const unsigned int NPT_ZIP_FILE_COMPRESSION_METHOD_NONE = 0x00;
54 const unsigned int NPT_ZIP_FILE_COMPRESSION_METHOD_DEFLATE = 0x08;
56 class NPT_ZipFile
58 public:
59 // types
60 class Entry {
61 public:
62 Entry(const unsigned char* data, NPT_Size data_available);
63 NPT_String m_Name;
64 NPT_UInt16 m_Flags;
65 NPT_UInt16 m_CompressionMethod;
66 NPT_UInt32 m_Crc32;
67 NPT_LargeSize m_CompressedSize;
68 NPT_LargeSize m_UncompressedSize;
69 NPT_UInt16 m_DiskNumber;
70 NPT_UInt16 m_InternalFileAttributes;
71 NPT_UInt32 m_ExternalFileAttributes;
72 NPT_Position m_RelativeOffset;
73 NPT_UInt32 m_DirectoryEntrySize;
76 // class methods
77 static NPT_Result Parse(NPT_InputStream& stream, NPT_ZipFile*& file);
78 static NPT_Result GetInputStream(Entry& entry, NPT_InputStreamReference& zip_stream, NPT_InputStream*& file_stream);
80 // accessors
81 NPT_Array<Entry>& GetEntries() { return m_Entries; }
83 private:
84 // constructor
85 NPT_ZipFile();
87 // members
88 NPT_Array<Entry> m_Entries;
91 /*----------------------------------------------------------------------
92 | NPT_Zip
93 +---------------------------------------------------------------------*/
94 const int NPT_ZIP_COMPRESSION_LEVEL_DEFAULT = -1;
95 const int NPT_ZIP_COMPRESSION_LEVEL_MIN = 0;
96 const int NPT_ZIP_COMPRESSION_LEVEL_MAX = 9;
97 const int NPT_ZIP_COMPRESSION_LEVEL_NONE = 0;
98 class NPT_Zip
100 public:
101 // class methods
102 static NPT_Result MapError(int err);
104 /**
105 * Compressed data format
107 typedef enum {
108 ZLIB,
109 GZIP
110 } Format;
113 * Deflate (i.e compress) a buffer
115 static NPT_Result Deflate(const NPT_DataBuffer& in,
116 NPT_DataBuffer& out,
117 int compression_level = NPT_ZIP_COMPRESSION_LEVEL_DEFAULT,
118 Format format = ZLIB);
121 * Inflate (i.e decompress) a buffer
123 static NPT_Result Inflate(const NPT_DataBuffer& in,
124 NPT_DataBuffer& out,
125 bool raw = false);
128 * Deflate (i.e compress) a file
130 static NPT_Result Deflate(NPT_File& in,
131 NPT_File& out,
132 int compression_level = NPT_ZIP_COMPRESSION_LEVEL_DEFAULT,
133 Format format = GZIP);
137 /*----------------------------------------------------------------------
138 | NPT_ZipInflatingInputStream
139 +---------------------------------------------------------------------*/
140 class NPT_ZipInflatingInputStream : public NPT_InputStream
142 public:
143 NPT_ZipInflatingInputStream(NPT_InputStreamReference& source, bool raw = false);
144 ~NPT_ZipInflatingInputStream() override;
146 // NPT_InputStream methods
147 NPT_Result Read(void* buffer,
148 NPT_Size bytes_to_read,
149 NPT_Size* bytes_read = NULL) override;
150 NPT_Result Seek(NPT_Position offset) override;
151 NPT_Result Tell(NPT_Position& offset) override;
152 NPT_Result GetSize(NPT_LargeSize& size) override;
153 NPT_Result GetAvailable(NPT_LargeSize& available) override;
155 private:
156 NPT_InputStreamReference m_Source;
157 NPT_Position m_Position;
158 NPT_ZipInflateState* m_State;
159 NPT_DataBuffer m_Buffer;
162 /*----------------------------------------------------------------------
163 | NPT_ZipInflatingOutputStream
164 +---------------------------------------------------------------------*/
166 /*----------------------------------------------------------------------
167 | NPT_ZipDeflatingInputStream
168 +---------------------------------------------------------------------*/
169 class NPT_ZipDeflatingInputStream : public NPT_InputStream
171 public:
172 NPT_ZipDeflatingInputStream(NPT_InputStreamReference& source,
173 int compression_level = NPT_ZIP_COMPRESSION_LEVEL_DEFAULT,
174 NPT_Zip::Format format = NPT_Zip::ZLIB);
175 ~NPT_ZipDeflatingInputStream() override;
177 // NPT_InputStream methods
178 NPT_Result Read(void* buffer,
179 NPT_Size bytes_to_read,
180 NPT_Size* bytes_read = NULL) override;
181 NPT_Result Seek(NPT_Position offset) override;
182 NPT_Result Tell(NPT_Position& offset) override;
183 NPT_Result GetSize(NPT_LargeSize& size) override;
184 NPT_Result GetAvailable(NPT_LargeSize& available) override;
186 private:
187 NPT_InputStreamReference m_Source;
188 NPT_Position m_Position;
189 bool m_Eos;
190 NPT_ZipDeflateState* m_State;
191 NPT_DataBuffer m_Buffer;
194 /*----------------------------------------------------------------------
195 | NPT_ZipDeflatingOutputStream
196 +---------------------------------------------------------------------*/
197 /*class NPT_ZipDeflatingOutputStream : public NPT_OutputStream
199 public:
200 NPT_ZipDeflatingOutputStream(NPT_OutputStreamReference& source,
201 int compression_level = NPT_ZIP_COMPRESSION_LEVEL_DEFAULT,
202 NPT_Zip::Format format = NPT_Zip::ZLIB);
203 NPT_ZipDeflatingOutputStream();
205 // NPT_OutputStream methods
206 virtual NPT_Result Write(void* buffer,
207 NPT_Size bytes_to_write,
208 NPT_Size* bytes_written = NULL);
209 virtual NPT_Result Seek(NPT_Position offset);
210 virtual NPT_Result Tell(NPT_Position& offset);
212 private:
213 NPT_OutputStreamReference m_Output;
214 NPT_Position m_Position;
215 bool m_Eos;
216 NPT_ZipDeflateState* m_State;
217 NPT_DataBuffer m_Buffer;
218 }; */
220 #endif // _NPT_ZIP_H_