blob: 7a6bb02a6f20b34df6b15f0c362e44ea14d2156c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef __ORCUS_ZIP_ARCHIVE_STREAM_HPP__
#define __ORCUS_ZIP_ARCHIVE_STREAM_HPP__
#include "env.hpp"
#include <cstdlib>
#include <cstdio>
#include <cstdint>
namespace orcus {
class ORCUS_PSR_DLLPUBLIC zip_archive_stream
{
public:
virtual ~zip_archive_stream();
virtual size_t size() const = 0;
virtual size_t tell() const = 0;
virtual void seek(size_t pos) = 0;
virtual void read(unsigned char* buffer, size_t length) const = 0;
};
/**
* Zip archive based on file descriptor. The caller needs to provide the
* file path to the zip archive.
*/
class ORCUS_PSR_DLLPUBLIC zip_archive_stream_fd : public zip_archive_stream
{
FILE* m_stream;
public:
zip_archive_stream_fd() = delete;
zip_archive_stream_fd(const char* filepath);
virtual ~zip_archive_stream_fd();
virtual size_t size() const;
virtual size_t tell() const;
virtual void seek(size_t pos);
virtual void read(unsigned char* buffer, size_t length) const;
};
/**
* Zip archive whose content is already loaded onto memory.
*/
class ORCUS_PSR_DLLPUBLIC zip_archive_stream_blob : public zip_archive_stream
{
const uint8_t* m_blob;
const uint8_t* m_cur;
std::size_t m_size;
public:
zip_archive_stream_blob() = delete;
zip_archive_stream_blob(const uint8_t* blob, std::size_t size);
virtual ~zip_archive_stream_blob();
virtual size_t size() const;
virtual size_t tell() const;
virtual void seek(size_t pos);
virtual void read(unsigned char* buffer, size_t length) const;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|