zipper.hh   zipper.hh 
skipping to change at line 29 skipping to change at line 29
#define zipper_hh #define zipper_hh
#include <stdexcept> #include <stdexcept>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <cstdint> #include <cstdint>
#include <sys/stat.h> // For mode_t #include <sys/stat.h> // For mode_t
#include <sys/time.h> // For timeval
/** /**
\mainpage libzipper C++ (de)compression library \mainpage libzipper C++ (de)compression library
\section intro Introduction \section intro Introduction
libzipper offers a flexible C++ interface for reading compressed files libzipper offers a flexible C++ interface for reading compressed files
in multiple formats. in multiple formats.
<a href="http://www.codesrc.com/src/libzipper">Homepage</a> <a href="http://www.codesrc.com/src/libzipper">Homepage</a>
libzipper aims to provide applications a transparent method of accessing libzipper aims to provide applications a transparent method of accessing
compressed data. eg. libzipper is suited to reading XML config files that compressed data. eg. libzipper is suited to reading XML config files that
are compressed to save space. are compressed to save space.
libzipper is not a general-purpose archive management library, as it libzipper is not a general-purpose archive management library, as it
does not provide access to the filesystem attributes of each file. does not provide access to the filesystem attributes of each file.
(ie. libzipper does not support the concepts of file owner, group, (ie. libzipper does not support the concepts of file owner, group or
permissions, or timestamps. permissions.
\section formats Supported Formats \section formats Supported Formats
<ul> <ul>
<li>gzip</li> <li>gzip</li>
<li>zip</li> <li>zip</li>
</ul> </ul>
\section example_read Reading a compressed file into memory \section example_read Reading a compressed file into memory
\code \code
#include <zipper.hh> #include <zipper.hh>
skipping to change at line 114 skipping to change at line 115
{ {
public: public:
MemReader(const vector<uint8_t>& data) : m_data(data) {} MemReader(const vector<uint8_t>& data) : m_data(data) {}
virtual const std::string& getSourceName() const virtual const std::string& getSourceName() const
{ {
static std::string Name("savedGame.dat"); static std::string Name("savedGame.dat");
return Name; return Name;
} }
virtual const timeval& getModTime() const
{
return zipper::s_now;
}
virtual zsize_t getSize() const { return m_data.size(); } virtual zsize_t getSize() const { return m_data.size(); }
virtual void readData(zsize_t offset, zsize_t bytes, uint8_t* dest) const virtual void readData(zsize_t offset, zsize_t bytes, uint8_t* dest) const
{ {
std::copy(&m_data[offset], &m_data[offset + bytes], dest); std::copy(&m_data[offset], &m_data[offset + bytes], dest);
} }
private: private:
std::vector<uint8_t> m_data; std::vector<uint8_t> m_data;
}; };
skipping to change at line 219 skipping to change at line 225
ContainerFormat format; ContainerFormat format;
/// %Container Internet Media Type (aka MIME type). /// %Container Internet Media Type (aka MIME type).
/// eg. "application/zip" /// eg. "application/zip"
std::string mediaType; std::string mediaType;
/// Bitmask comprised of CapabilityBits enum values. /// Bitmask comprised of CapabilityBits enum values.
uint32_t capabilities; uint32_t capabilities;
}; };
/// \brief When passed as a method parameter, it requests that the
/// current time be used instead.
extern const timeval s_now;
/// \brief Returns the capability details of the given format. /// \brief Returns the capability details of the given format.
const Container& getContainer(ContainerFormat format); const Container& getContainer(ContainerFormat format);
/// \brief Base class for all exceptions thrown by libzipper /// \brief Base class for all exceptions thrown by libzipper
class Exception : public std::runtime_error class Exception : public std::runtime_error
{ {
public: public:
/// Exception ctor /// Exception ctor
/// \param what A description of the error encountered. /// \param what A description of the error encountered.
Exception(const std::string& what); Exception(const std::string& what);
skipping to change at line 288 skipping to change at line 298
public: public:
/// Reader dtor /// Reader dtor
virtual ~Reader(); virtual ~Reader();
/// Returns a name for this source of the data. /// Returns a name for this source of the data.
/// ///
/// For file-based Reader implementations, this would normal ly be /// For file-based Reader implementations, this would normal ly be
/// the input filename. /// the input filename.
virtual const std::string& getSourceName() const = 0; virtual const std::string& getSourceName() const = 0;
/// Return the last-modified timestamp of the data.
/// If the special s_now value is returned, the current time
should be
/// used instead.
virtual const timeval& getModTime() const = 0;
/// Returns the number of bytes available via readData() /// Returns the number of bytes available via readData()
/// ///
/// \invariant getSize() is stable throughout the lifetime /// \invariant getSize() is stable throughout the lifetime
/// of the Reader instance. /// of the Reader instance.
virtual zsize_t getSize() const = 0; virtual zsize_t getSize() const = 0;
/// Copies data into the dest buffer /// Copies data into the dest buffer
/// ///
/// An exception must be thrown if it is not possible to cop y the /// An exception must be thrown if it is not possible to cop y the
/// requested data into the supplied buffer (eg. file IO err or). /// requested data into the supplied buffer (eg. file IO err or).
skipping to change at line 338 skipping to change at line 354
/// when it is no longer needed. /// when it is no longer needed.
FileReader(const std::string& filename, int fd, bool closeFd ); FileReader(const std::string& filename, int fd, bool closeFd );
/// FileReader dtor /// FileReader dtor
virtual ~FileReader(); virtual ~FileReader();
/// Inherited from Reader /// Inherited from Reader
virtual const std::string& getSourceName() const; virtual const std::string& getSourceName() const;
/// Inherited from Reader /// Inherited from Reader
virtual const timeval& getModTime() const;
/// Inherited from Reader
virtual zsize_t getSize() const; virtual zsize_t getSize() const;
/// Inherited from Reader /// Inherited from Reader
virtual void readData( virtual void readData(
zsize_t offset, zsize_t bytes, uint8_t* dest zsize_t offset, zsize_t bytes, uint8_t* dest
) const; ) const;
private: private:
FileReader(const FileReader&); FileReader(const FileReader&);
FileReader& operator=(const FileReader&); FileReader& operator=(const FileReader&);
skipping to change at line 407 skipping to change at line 426
public: public:
/// Write data to the supplied file. /// Write data to the supplied file.
/// If the file already exists, it will be truncated. /// If the file already exists, it will be truncated.
/// If the file does not exist, it will be created with the /// If the file does not exist, it will be created with the
/// given permissions. /// given permissions.
/// ///
/// \param filename The file to open for writing. /// \param filename The file to open for writing.
/// ///
/// \param createPermissions The permissions set on the file if it is to /// \param createPermissions The permissions set on the file if it is to
/// be created. /// be created.
FileWriter(const std::string& filename, mode_t createPermiss ///
ions); /// \param modTime Set a specific modification time on the c
reated file.
/// If the special s_now value is provided, the current time
will be
/// used.
///
FileWriter(
const std::string& filename,
mode_t createPermissions = 0664,
const timeval& modTime = s_now);
/// Write data to the supplied file. /// Write data to the supplied file.
/// ///
/// \param filename The filename reported in any exception e rror /// \param filename The filename reported in any exception e rror
/// messages. This name is arbitary, and does not need to b e /// messages. This name is arbitary, and does not need to b e
/// related to fd. /// related to fd.
/// ///
/// \param fd The descriptor to write data to. The descript or /// \param fd The descriptor to write data to. The descript or
/// must be open for writing in blocking mode. /// must be open for writing in blocking mode.
/// ///
skipping to change at line 481 skipping to change at line 508
virtual zsize_t getCompressedSize() const = 0; virtual zsize_t getCompressedSize() const = 0;
/// Return the uncompressed size of the file /// Return the uncompressed size of the file
/// ///
/// The decompress method will pass exactly this number of b ytes /// The decompress method will pass exactly this number of b ytes
/// to the Writer. /// to the Writer.
/// ///
/// getUncompressedSize() will return -1 of the FileSize cap ability /// getUncompressedSize() will return -1 of the FileSize cap ability
/// bit of the container is false. /// bit of the container is false.
virtual zsize_t getUncompressedSize() const = 0; virtual zsize_t getUncompressedSize() const = 0;
/// Return the modification time of the original file
virtual const timeval& getModificationTime() const = 0;
}; };
/// \typedef CompressedFilePtr /// \typedef CompressedFilePtr
/// A shared pointer to a CompressedFile /// A shared pointer to a CompressedFile
typedef std::shared_ptr<CompressedFile> CompressedFilePtr; typedef std::shared_ptr<CompressedFile> CompressedFilePtr;
/// \brief Decompressor detects the compressed archive type of the d ata, /// \brief Decompressor detects the compressed archive type of the d ata,
/// and creates suitable CompressedFile instances to access the comp ressed /// and creates suitable CompressedFile instances to access the comp ressed
/// data. /// data.
class Decompressor class Decompressor
{ {
skipping to change at line 527 skipping to change at line 557
}; };
/// \brief Compressor creates a compressed archive from the supplied /// \brief Compressor creates a compressed archive from the supplied
/// Reader objects. /// Reader objects.
/// data. /// data.
class Compressor class Compressor
{ {
public: public:
/// Create a Compressor to output the given compressed archi ved format /// Create a Compressor to output the given compressed archi ved format
/// to writer. /// to writer.
/// \param writer destination of the compressed data
/// \param format determines the output archive file type to
/// create.
Compressor(ContainerFormat format, const WriterPtr& writer); Compressor(ContainerFormat format, const WriterPtr& writer);
/// Create a Compressor to output the given compressed archi ved format /// Create a Compressor to output the given compressed archi ved format
/// to writer. /// to writer.
/// ///
/// \param writer must remain in scope for the lifetime of t /// \param writer is the destination of the compressed data.
he writer
/// Compressor. /// must remain in scope for the lifetime of the Compressor.
/// \param format determines the output archive file type to
/// create.
Compressor(ContainerFormat format, Writer& writer); Compressor(ContainerFormat format, Writer& writer);
/// \brief Compressor dtor /// \brief Compressor dtor
/// ///
/// Additional data may be passed to writer (given in ctor) to close /// Additional data may be passed to writer (given in ctor) to close
/// the compressed archive. /// the compressed archive.
~Compressor(); ~Compressor();
/// Compress the data given by reader, and add it to the com pressed /// Compress the data given by reader, and add it to the com pressed
/// archive. /// archive.
 End of changes. 10 change blocks. 
7 lines changed or deleted 43 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/