zipios 2.3.4
Zipios -- a small C++ library providing easy access to .zip files.
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-2022 Made to Order Software Corp. All Rights Reserved
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"
39
40#include <memory>
41#include <vector>
42
43
44namespace zipios
45{
46
47
48enum class StorageMethod : uint8_t
49{
50 STORED = 0,
51 SHRUNK = 1,
52 REDUCED1 = 2,
53 REDUCED2 = 3,
54 REDUCED3 = 4,
55 REDUCED4 = 5,
56 IMPLODED = 6,
57 TOKENIZED = 7,
58 DEFLATED = 8,
59 DEFLATED64 = 9,
60 OLD_TERSE = 10,
61 RESERVED11 = 11,
62 BZIP2 = 12,
63 REVERVED13 = 13,
64 LZMA = 14,
65 RESERVED15 = 15,
66 RESERVED16 = 16,
67 RESERVED17 = 17,
68 NEW_TERSE = 18,
69 LZ77 = 19,
70 WAVPACK = 97,
71 PPMD_I_1 = 98
72};
73
74
76{
77public:
78 typedef std::shared_ptr<FileEntry> pointer_t;
79 typedef std::vector<pointer_t> vector_t;
80 typedef std::vector<unsigned char> buffer_t;
81 typedef uint32_t crc32_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 std::size_t getCompressedSize() const;
100 virtual crc32_t getCrc() const;
101 std::streampos getEntryOffset() const;
102 virtual buffer_t getExtra() const;
103 virtual std::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 std::size_t getSize() const;
110 getTime() const;
111 virtual std::time_t getUnixTime() const;
112 bool hasCrc() const;
113 virtual bool isDirectory() const;
114 virtual bool isEqual(FileEntry const & file_entry) const;
115 virtual bool isValid() const;
116 virtual void setComment(std::string const & comment);
117 virtual void setCompressedSize(size_t size);
118 virtual void setCrc(crc32_t crc);
119 void setEntryOffset(std::streampos offset);
120 virtual void setExtra(buffer_t const & extra);
121 virtual void setLevel(CompressionLevel level);
122 virtual void setMethod(StorageMethod method);
123 virtual void setSize(size_t size);
124 virtual void setTime(DOSDateTime::dosdatetime_t time);
125 virtual void setUnixTime(std::time_t time);
126 virtual std::string toString() const;
127
128 virtual void read(std::istream & is);
129 virtual void write(std::ostream & os);
130
131protected:
133 std::string m_comment;
134 std::size_t m_uncompressed_size = 0;
135 time_t m_unix_time = 0;
136 std::streampos m_entry_offset = 0;
139 uint32_t m_crc_32 = 0;
141 bool m_has_crc_32 = false;
142 bool m_valid = false;
143};
144
145
146std::ostream & operator << (std::ostream & os, FileEntry const & entry);
147
148
149} // zipios namespace
150
151// Local Variables:
152// mode: cpp
153// indent-tabs-mode: nil
154// c-basic-offset: 4
155// tab-width: 4
156// End:
157
158// vim: ts=4 sw=4 et
159#endif
A FileEntry represents an entry in a FileCollection.
Definition fileentry.hpp:76
std::vector< unsigned char > buffer_t
Definition fileentry.hpp:80
std::size_t m_uncompressed_size
std::shared_ptr< FileEntry > pointer_t
Definition fileentry.hpp:78
StorageMethod m_compress_method
virtual std::string getFileName() const
Return the basename of this entry.
virtual std::size_t getSize() const
Retrieve the size of the file when uncompressed.
std::string m_comment
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 void setComment(std::string const &comment)
Set the comment field for the FileEntry.
buffer_t m_extra_field
virtual std::size_t getCompressedSize() const
Retrieve the size of the file when compressed.
static CompressionLevel const COMPRESSION_LEVEL_MAXIMUM
Definition fileentry.hpp:92
virtual std::string getComment() const
Retrieve the comment of the file entry.
bool hasCrc() const
Check whether the CRC32 was defined.
virtual void setTime(DOSDateTime::dosdatetime_t time)
Set the FileEntry time using a DOS time.
virtual std::string getName() const
Return the filename of the entry.
virtual bool isValid() const
Check whether this entry is valid.
virtual void setSize(size_t size)
Sets the size field for the entry.
virtual void setUnixTime(std::time_t time)
Sets the time field in Unix time format for the entry.
virtual void setExtra(buffer_t const &extra)
Set the extra field buffer.
virtual void read(std::istream &is)
Read this FileEntry from the input stream.
virtual void setLevel(CompressionLevel level)
Define the level of compression to use by this FileEntry.
static CompressionLevel const COMPRESSION_LEVEL_DEFAULT
Definition fileentry.hpp:87
virtual bool isDirectory() const
Check whether the filename represents a directory.
CompressionLevel m_compression_level
std::streampos m_entry_offset
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.
virtual StorageMethod getMethod() const
Return the method used to create this entry.
static CompressionLevel const COMPRESSION_LEVEL_FASTEST
Definition fileentry.hpp:89
virtual CompressionLevel getLevel() const
Retrieve the compression level.
virtual std::string toString() const
Returns a human-readable string representation of the entry.
virtual crc32_t getCrc() const
Return the CRC of the entry.
virtual void setCompressedSize(size_t size)
Set the size when the file is compressed.
virtual buffer_t getExtra() const
Some extra data to be stored along the entry.
virtual DOSDateTime::dosdatetime_t getTime() const
Get the MS-DOS date/time of this entry.
std::streampos getEntryOffset() const
Get the offset of this entry in a Zip archive.
std::vector< pointer_t > vector_t
Definition fileentry.hpp:79
virtual std::time_t getUnixTime() const
Get the Unix date/time of this entry.
virtual bool isEqual(FileEntry const &file_entry) const
Compare two file entries for equality.
virtual void write(std::ostream &os)
Write this FileEntry to the output stream.
virtual void setMethod(StorageMethod method)
Sets the storage method field for the entry.
virtual std::size_t getHeaderSize() const
Retrieve the size of the header.
virtual ~FileEntry()
Clean up a FileEntry object.
void setEntryOffset(std::streampos offset)
Defines the position of the entry in a Zip archive.
static CompressionLevel const COMPRESSION_LEVEL_SMALLEST
Definition fileentry.hpp:88
Handle a file path and name and its statistics.
Definition filepath.hpp:47
Define a type to manage date and time in MS-DOS format.
Define the zipios::FilePath class.
The zipios namespace includes the Zipios library definitions.
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:49