fileentry.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef ZIPIOS_FILEENTRY_HPP
3#define ZIPIOS_FILEENTRY_HPP
4
5/*
6 Zipios++ - a small C++ library that provides easy access to .zip files.
7
8 Copyright (C) 2000-2007 Thomas Sondergaard
9 Copyright (C) 2015-2017 Made to Order Software Corporation
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
37#include "zipios/filepath.hpp"
38
39#include <memory>
40#include <vector>
41
42
43namespace zipios
44{
45
46
47enum class StorageMethod : uint8_t
48{
49 STORED = 0,
50 SHRUNK = 1,
51 REDUCED1 = 2,
52 REDUCED2 = 3,
53 REDUCED3 = 4,
54 REDUCED4 = 5,
55 IMPLODED = 6,
56 TOKENIZED = 7,
57 DEFLATED = 8,
58 DEFLATED64 = 9,
59 OLD_TERSE = 10,
60 RESERVED11 = 11,
61 BZIP2 = 12,
62 REVERVED13 = 13,
63 LZMA = 14,
64 RESERVED15 = 15,
65 RESERVED16 = 16,
66 RESERVED17 = 17,
67 NEW_TERSE = 18,
68 LZ77 = 19,
69 WAVPACK = 97,
70 PPMD_I_1 = 98
71};
72
73
75{
76public:
77 typedef std::shared_ptr<FileEntry> pointer_t;
78 typedef std::vector<pointer_t> vector_t;
79 typedef std::vector<unsigned char> buffer_t;
80 typedef uint32_t crc32_t;
81 typedef uint32_t dostime_t;
82
83 // we use our own compression level type, it gets converted as
84 // required when the level is to be used by a compression scheme
85 typedef int CompressionLevel;
86
93
94 FileEntry(FilePath const & filename, std::string const & comment = std::string());
95 virtual pointer_t clone() const = 0;
96 virtual ~FileEntry();
97
98 virtual std::string getComment() const;
99 virtual size_t getCompressedSize() const;
100 virtual crc32_t getCrc() const;
101 std::streampos getEntryOffset() const;
102 virtual buffer_t getExtra() const;
103 virtual size_t getHeaderSize() const;
104 virtual CompressionLevel getLevel() const;
105 virtual StorageMethod getMethod() const;
106 virtual std::string getName() const;
107 virtual std::string getFileName() const;
108 virtual size_t getSize() const;
109 virtual dostime_t getTime() const;
110 virtual std::time_t getUnixTime() const;
111 bool hasCrc() const;
112 virtual bool isDirectory() const;
113 virtual bool isEqual(FileEntry const& file_entry) const;
114 virtual bool isValid() const;
115 virtual void setComment(std::string const& comment);
116 virtual void setCompressedSize(size_t size);
117 virtual void setCrc(crc32_t crc);
118 void setEntryOffset(std::streampos offset);
119 virtual void setExtra(buffer_t const& extra);
120 virtual void setLevel(CompressionLevel level);
121 virtual void setMethod(StorageMethod method);
122 virtual void setSize(size_t size);
123 virtual void setTime(dostime_t time);
124 virtual void setUnixTime(std::time_t time);
125 virtual std::string toString() const;
126
127 virtual void read(std::istream& is);
128 virtual void write(std::ostream& os);
129
130protected:
132 std::string m_comment;
134 time_t m_unix_time = 0;
135 std::streampos m_entry_offset = 0;
138 uint32_t m_crc_32 = 0;
140 bool m_has_crc_32 = false;
141 bool m_valid = false;
142};
143
144
145std::ostream& operator << (std::ostream& os, FileEntry const& entry);
146
147
148} // zipios namespace
149
150// Local Variables:
151// mode: cpp
152// indent-tabs-mode: nil
153// c-basic-offset: 4
154// tab-width: 4
155// End:
156
157// vim: ts=4 sw=4 et
158#endif
A FileEntry represents an entry in a FileCollection.
Definition: fileentry.hpp:75
std::vector< unsigned char > buffer_t
Definition: fileentry.hpp:79
virtual size_t getSize() const
Retrieve the size of the file when uncompressed.
Definition: fileentry.cpp:332
std::shared_ptr< FileEntry > pointer_t
Definition: fileentry.hpp:77
uint32_t dostime_t
Definition: fileentry.hpp:81
StorageMethod m_compress_method
Definition: fileentry.hpp:136
virtual std::string getFileName() const
Return the basename of this entry.
Definition: fileentry.cpp:320
std::string m_comment
Definition: fileentry.hpp:132
virtual void setTime(dostime_t time)
Set the FileEntry time using a DOS time.
Definition: fileentry.cpp:653
int CompressionLevel
The compression level to be used to save an entry.
Definition: fileentry.hpp:85
static CompressionLevel const COMPRESSION_LEVEL_MINIMUM
Definition: fileentry.hpp:91
virtual dostime_t getTime() const
Get the MS-DOS date/time of this entry.
Definition: fileentry.cpp:349
virtual void setComment(std::string const &comment)
Set the comment field for the FileEntry.
Definition: fileentry.cpp:461
buffer_t m_extra_field
Definition: fileentry.hpp:139
virtual size_t getCompressedSize() const
Retrive the size of the file when compressed.
Definition: fileentry.cpp:164
static CompressionLevel const COMPRESSION_LEVEL_MAXIMUM
Definition: fileentry.hpp:92
virtual std::string getComment() const
Retrieve the comment of the file entry.
Definition: fileentry.cpp:150
bool hasCrc() const
Check whether the CRC32 was defined.
Definition: fileentry.cpp:388
virtual std::string getName() const
Return the filename of the entry.
Definition: fileentry.cpp:303
virtual bool isValid() const
Check whether this entry is valid.
Definition: fileentry.cpp:447
virtual void setSize(size_t size)
Sets the size field for the entry.
Definition: fileentry.cpp:637
virtual void setUnixTime(std::time_t time)
Sets the time field in Unix time format for the entry.
Definition: fileentry.cpp:668
virtual void setExtra(buffer_t const &extra)
Set the extra field buffer.
Definition: fileentry.cpp:527
virtual void read(std::istream &is)
Read this FileEntry from the input stream.
Definition: fileentry.cpp:724
virtual void setLevel(CompressionLevel level)
Define the level of compression to use by this FileEntry.
Definition: fileentry.cpp:548
static CompressionLevel const COMPRESSION_LEVEL_DEFAULT
Definition: fileentry.hpp:87
size_t m_uncompressed_size
Definition: fileentry.hpp:133
virtual bool isDirectory() const
Check whether the filename represents a directory.
Definition: fileentry.cpp:402
CompressionLevel m_compression_level
Definition: fileentry.hpp:137
std::streampos m_entry_offset
Definition: fileentry.hpp:135
static CompressionLevel const COMPRESSION_LEVEL_NONE
Definition: fileentry.hpp:90
virtual pointer_t clone() const =0
Create a clone of a file entry.
virtual void setCrc(crc32_t crc)
Save the CRC of the entry.
Definition: fileentry.cpp:492
virtual StorageMethod getMethod() const
Return the method used to create this entry.
Definition: fileentry.cpp:282
static CompressionLevel const COMPRESSION_LEVEL_FASTEST
Definition: fileentry.hpp:89
virtual CompressionLevel getLevel() const
Retrieve the compression level.
Definition: fileentry.cpp:262
virtual std::string toString() const
Returns a human-readable string representation of the entry.
Definition: fileentry.cpp:683
virtual crc32_t getCrc() const
Return the CRC of the entry.
Definition: fileentry.cpp:182
virtual void setCompressedSize(size_t size)
Set the size when the file is compressed.
Definition: fileentry.cpp:480
virtual buffer_t getExtra() const
Some extra data to be stored along the entry.
Definition: fileentry.cpp:222
std::streampos getEntryOffset() const
Get the offset of this entry in a Zip archive.
Definition: fileentry.cpp:202
FilePath m_filename
Definition: fileentry.hpp:131
std::vector< pointer_t > vector_t
Definition: fileentry.hpp:78
virtual std::time_t getUnixTime() const
Get the Unix date/time of this entry.
Definition: fileentry.cpp:374
virtual bool isEqual(FileEntry const &file_entry) const
Compare two file entries for equality.
Definition: fileentry.cpp:425
virtual void write(std::ostream &os)
Write this FileEntry to the output stream.
Definition: fileentry.cpp:742
virtual void setMethod(StorageMethod method)
Sets the storage method field for the entry.
Definition: fileentry.cpp:585
uint32_t crc32_t
Definition: fileentry.hpp:80
virtual size_t getHeaderSize() const
Retrieve the size of the header.
Definition: fileentry.cpp:237
virtual ~FileEntry()
Clean up a FileEntry object.
Definition: fileentry.cpp:134
void setEntryOffset(std::streampos offset)
Defines the position of the entry in a Zip archive.
Definition: fileentry.cpp:512
static CompressionLevel const COMPRESSION_LEVEL_SMALLEST
Definition: fileentry.hpp:88
Handle a file path and name and its statistics.
Definition: filepath.hpp:47
Define the zipios::FilePath class.
The zipios namespace includes the Zipios++ library definitions.
Definition: backbuffer.cpp:36
std::ostream & operator<<(std::ostream &os, FileCollection const &collection)
Write a FileCollection to the output stream.
StorageMethod
The types used with FileEntry::setMethod and FileEntry::getMethod.
Definition: fileentry.hpp:48