zipios 2.3.4
Zipios -- a small C++ library providing easy access to .zip files.
directoryentry.cpp
Go to the documentation of this file.
1/*
2 Zipios -- a small C++ library that provides easy access to .zip files.
3
4 Copyright (C) 2000-2007 Thomas Sondergaard
5 Copyright (c) 2015-2022 Made to Order Software Corp. All Rights Reserved
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
30
32
33#include "zipios_common.hpp"
34
35#include <fstream>
36#include <zlib.h>
37
38
39namespace zipios
40{
41
61DirectoryEntry::DirectoryEntry(FilePath const & filename, std::string const & comment)
62 : FileEntry(filename, comment)
63{
65 if(m_valid)
66 {
69 }
70}
71
72
84{
85 return std::make_shared<DirectoryEntry>(*this);
86}
87
88
98
99
113bool DirectoryEntry::isEqual(FileEntry const & file_entry) const
114{
115 DirectoryEntry const * const de(dynamic_cast<DirectoryEntry const * const>(&file_entry));
116 if(de == nullptr)
117 {
118 return false;
119 }
120 return FileEntry::isEqual(file_entry);
121}
122
123
137{
138 uint32_t result(crc32(0L, Z_NULL, 0));
139
141 {
142 // TODO: I tried to use std::basic_ifstream<Bytef> to avoid the
143 // reinterpret_cast<>(), but somehow that doesn't work at all
144 //
145 std::ifstream in;
146 in.open(m_filename);
147 if(!in.is_open())
148 {
149 throw IOException(
150 "Can't open file \""
152 + "\".");
153 }
154
155 for(;;)
156 {
157 Bytef buf[64 * 1024];
158 in.read(reinterpret_cast<char *>(buf), sizeof(buf));
159 if(in.gcount() == 0)
160 {
161 break;
162 }
163 result = crc32(result, buf, in.gcount());
164 }
165 }
166
167 return result;
168}
169
170
171} // zipios namespace
172
173// Local Variables:
174// mode: cpp
175// indent-tabs-mode: nil
176// c-basic-offset: 4
177// tab-width: 4
178// End:
179
180// vim: ts=4 sw=4 et
A file entry that does not use compression.
virtual ~DirectoryEntry() override
Clean up a DirectoryEntry object.
virtual pointer_t clone() const override
Create a copy of the DirectoryEntry.
virtual bool isEqual(FileEntry const &file_entry) const override
Compare two file entries for equality.
DirectoryEntry(FilePath const &filename, std::string const &comment=std::string())
Initialize a DirectoryEntry object.
uint32_t computeCRC32() const
Compute the CRC32 of this file.
A FileEntry represents an entry in a FileCollection.
Definition fileentry.hpp:76
std::size_t m_uncompressed_size
std::shared_ptr< FileEntry > pointer_t
Definition fileentry.hpp:78
virtual bool isEqual(FileEntry const &file_entry) const
Compare two file entries for equality.
Handle a file path and name and its statistics.
Definition filepath.hpp:47
bool isDirectory() const
Check whether the file is a directory.
Definition filepath.cpp:422
std::time_t lastModificationTime() const
Get the last modification time of the file.
Definition filepath.cpp:521
size_t fileSize() const
Get the size of the file.
Definition filepath.cpp:504
bool isRegular() const
Check whether the file is a regular file.
Definition filepath.cpp:408
std::string filename() const
Retrieve the basename.
Definition filepath.cpp:315
An IOException is used to signal an I/O error.
Define the zipios::DirectoryEntry class.
The zipios namespace includes the Zipios library definitions.
Various functions used throughout the library.
Various exceptions used throughout the Zipios library, all based on zipios::Exception.