CACAO
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
source
cacao
src
vm
zip.hpp
Go to the documentation of this file.
1
/* src/vm/zip.hpp - ZIP file handling for bootstrap classloader
2
3
Copyright (C) 1996-2013
4
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6
This file is part of CACAO.
7
8
This program is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License as
10
published by the Free Software Foundation; either version 2, or (at
11
your option) any later version.
12
13
This program is distributed in the hope that it will be useful, but
14
WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
02110-1301, USA.
22
23
*/
24
25
26
#ifndef ZIP_HPP_
27
#define ZIP_HPP_ 1
28
29
#include "config.h"
// for ENABLE_ZLIB
30
31
#ifdef ENABLE_ZLIB
32
33
#include <cstddef>
// for size_t
34
#include <stdint.h>
// for uint8_t
35
36
#include "
toolbox/hashtable.hpp
"
// for InsertOnlyStringEntry, etc
37
38
#include "
vm/types.hpp
"
// for u2, u4, u1
39
#include "
vm/utf8.hpp
"
// for Utf8String
40
41
42
/* Local file header ***********************************************************
43
44
local file header signature 4 bytes (0x04034b50)
45
version needed to extract 2 bytes
46
general purpose bit flag 2 bytes
47
compression method 2 bytes
48
last mod file time 2 bytes
49
last mod file date 2 bytes
50
crc-32 4 bytes
51
compressed size 4 bytes
52
uncompressed size 4 bytes
53
file name length 2 bytes
54
extra field length 2 bytes
55
56
file name (variable size)
57
extra field (variable size)
58
59
*******************************************************************************/
60
61
#define LFH_HEADER_SIZE 30
62
63
#define LFH_SIGNATURE 0x04034b50
64
#define LFH_FILE_NAME_LENGTH 26
65
#define LFH_EXTRA_FIELD_LENGTH 28
66
67
struct
lfh
{
68
u2
compressionmethod
;
69
u4
compressedsize
;
70
u4
uncompressedsize
;
71
u2
filenamelength
;
72
u2
extrafieldlength
;
73
};
74
75
/* hashtable_zipfile_entry ****************************************************/
76
77
struct
ZipFileEntry
{
78
Utf8String
filename
;
79
u2
compressionmethod
;
80
u4
compressedsize
;
81
u4
uncompressedsize
;
82
u1
*
data
;
83
84
/***
85
* Load data from zipped file into memory
86
*
87
* `dst' must have room for `uncompressedsize' bytes.
88
*/
89
void
get
(uint8_t *dst)
const
;
90
91
/// interface to HashTable
92
size_t
hash
()
const
{
return
filename
.
hash
(); }
93
94
Utf8String
key
()
const
{
return
filename
; }
95
void
set_key
(
Utf8String
u) {
filename
= u; }
96
};
97
98
class
ZipFile
{
99
typedef
HashTable<InsertOnlyNamedEntry<ZipFileEntry>
>
Table
;
100
public
:
101
typedef
Table::Iterator
Iterator
;
102
typedef
Table::EntryRef
EntryRef
;
103
104
/// Load zip archive
105
static
ZipFile
*
open
(
const
char
*path);
106
107
/// Find file in zip archive
108
EntryRef
find
(
Utf8String
filename) {
return
table
.
find
(filename); }
109
110
/// Allows iteration over all entries in zip archive
111
Iterator
begin
() {
return
table
.
begin
(); }
112
Iterator
end
() {
return
table
.
end
(); }
113
private
:
114
ZipFile
(
size_t
capacity) :
table
(capacity) {}
115
116
Table
table
;
117
};
118
119
#endif // ENABLE_ZLIB
120
121
#endif // ZIP_HPP_
122
123
124
/*
125
* These are local overrides for various environment variables in Emacs.
126
* Please do not remove this and leave it at the end of the file, where
127
* Emacs will automagically detect them.
128
* ---------------------------------------------------------------------
129
* Local variables:
130
* mode: c++
131
* indent-tabs-mode: t
132
* c-basic-offset: 4
133
* tab-width: 4
134
* End:
135
* vim:noexpandtab:sw=4:ts=4:
136
*/
ZipFileEntry
Definition:
zip.hpp:77
HashTable
Definition:
hashtable.hpp:112
HashTable::end
Iterator end()
Definition:
hashtable.hpp:453
lfh::extrafieldlength
u2 extrafieldlength
Definition:
zip.hpp:72
ZipFile::ZipFile
ZipFile(size_t capacity)
Definition:
zip.hpp:114
ZipFileEntry::uncompressedsize
u4 uncompressedsize
Definition:
zip.hpp:81
ZipFileEntry::filename
Utf8String filename
Definition:
zip.hpp:78
u1
uint8_t u1
Definition:
types.hpp:40
Utf8String::hash
size_t hash() const
Definition:
utf8.hpp:137
ZipFile
Definition:
zip.hpp:98
hashtable.hpp
ZipFile::table
Table table
Definition:
zip.hpp:116
types.hpp
ZipFile::begin
Iterator begin()
Allows iteration over all entries in zip archive.
Definition:
zip.hpp:111
ZipFileEntry::set_key
void set_key(Utf8String u)
Definition:
zip.hpp:95
ZipFileEntry::data
u1 * data
Definition:
zip.hpp:82
u2
uint16_t u2
Definition:
types.hpp:43
ZipFileEntry::compressionmethod
u2 compressionmethod
Definition:
zip.hpp:79
ZipFile::EntryRef
Table::EntryRef EntryRef
Definition:
zip.hpp:102
lfh::compressionmethod
u2 compressionmethod
Definition:
zip.hpp:68
ZipFileEntry::key
Utf8String key() const
Definition:
zip.hpp:94
ZipFileEntry::compressedsize
u4 compressedsize
Definition:
zip.hpp:80
ZipFile::Table
HashTable< InsertOnlyNamedEntry< ZipFileEntry > > Table
Definition:
zip.hpp:99
ZipFile::find
EntryRef find(Utf8String filename)
Find file in zip archive.
Definition:
zip.hpp:108
lfh
Definition:
zip.hpp:67
ZipFile::end
Iterator end()
Definition:
zip.hpp:112
u4
uint32_t u4
Definition:
types.hpp:46
HashTable::find
EntryRef find(const T &t)
Definition:
hashtable.hpp:215
lfh::uncompressedsize
u4 uncompressedsize
Definition:
zip.hpp:70
lfh::compressedsize
u4 compressedsize
Definition:
zip.hpp:69
utf8.hpp
ZipFileEntry::hash
size_t hash() const
interface to HashTable
Definition:
zip.hpp:92
HashTable::begin
Iterator begin()
Definition:
hashtable.hpp:442
lfh::filenamelength
u2 filenamelength
Definition:
zip.hpp:71
ZipFile::open
static ZipFile * open(const char *path)
Load zip archive.
Definition:
zip.cpp:160
Utf8String
Definition:
utf8.hpp:59
ZipFile::Iterator
Table::Iterator Iterator
Definition:
zip.hpp:101
Generated on Fri Aug 4 2017 03:01:55 for CACAO by
1.8.5