Skip to content

Commit e489190

Browse files
author
Yuta Imaya
committed
Merge branch 'release/0.1.4'
2 parents be5e008 + 666cdec commit e489190

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2124
-1021
lines changed

‎README.md

+111-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
zlib.js
22
=======
33

4-
zlib.js は ZLIB(RFC1950), DEFLATE(RFC1951), GZIP(RFC1952) の JavaScript 実装です。
4+
zlib.js は ZLIB(RFC1950), DEFLATE(RFC1951), GZIP(RFC1952), PKZIP の JavaScript 実装です。
55

66

77
使い方
@@ -18,6 +18,9 @@ bin ディレクトリから必要なものを利用してください。
1818
+ (GZIP)
1919
* gzip.min.js: GZIP
2020
* gunzip.min.js: GUNZIP
21+
+ (PKZIP)
22+
* zip.min.js ZIP
23+
* unzip.min.js UNZIP
2124
- node-zlib.js: (ZLIB + GZIP for node.js)
2225

2326

@@ -26,18 +29,22 @@ bin ディレクトリから必要なものを利用してください。
2629

2730
#### ZLIB
2831

29-
var defalte = new Zlib.Deflate(plain);
30-
var compressed = deflate.compress();
31-
32+
```js
33+
// plain = Array.<number> or Uint8Array
34+
var defalte = new Zlib.Deflate(plain);
35+
var compressed = deflate.compress();
36+
```
3237

3338
##### ZLIB Option
3439

3540
<code>Zlib.Deflate</code> の第二引数にオブジェクトを渡す事で圧縮オプションを指定する事が出来ます。
3641

37-
{
38-
compressionType: Zlib.Deflate.CompressionType, // 圧縮タイプ
39-
lazy: number // lazy matching の閾値
40-
}
42+
```js
43+
{
44+
compressionType: Zlib.Deflate.CompressionType, // 圧縮タイプ
45+
lazy: number // lazy matching の閾値
46+
}
47+
```
4148

4249
<code>Zlib.Deflate.CompressionType</code> は
4350
<code>NONE</code>(無圧縮), <code>FIXED</code>(固定ハフマン符号), <code>DYNAMIC</code>(動的ハフマン符号) から選択する事ができます。
@@ -52,23 +59,75 @@ Lazy Matching とは、LZSS のマッチ長が閾値より低かった場合、
5259
GZIP の実装は現在不完全ですが、ただの圧縮コンテナとして使用する場合には特に問題はありません。
5360
zlib.js を用いて作成された GZIP の OS は、自動的に UNKNOWN に設定されます。
5461

55-
var gzip = new Zlib.Gzip(plain);
56-
var compressed = gzip.compress();
62+
```js
63+
// plain = Array.<number> or Uint8Array
64+
var gzip = new Zlib.Gzip(plain);
65+
var compressed = gzip.compress();
66+
```
5767

5868

5969
##### GZIP Option
6070

61-
{
62-
deflateOptions: Object, // deflate option (ZLIB Option 参照)
63-
flags: {
64-
fname: boolean, // ファイル名を使用するか
65-
comment: boolean, // コメントを使用するか
66-
fhcrc: boolean // FHCRC を使用するか
67-
},
68-
filename: string, // flags.fname が true のと��に書き込むファイル名
69-
comment: string // flags.comment が true のときに書き込むコメント
71+
```js
72+
{
73+
deflateOptions: Object, // deflate option (ZLIB Option 参照)
74+
flags: {
75+
fname: boolean, // ファイル名を使用するか
76+
comment: boolean, // コメントを使用するか
77+
fhcrc: boolean // FHCRC を使用するか
78+
},
79+
filename: string, // flags.fname が true のときに書き込むファイル名
80+
comment: string // flags.comment が true のときに書き込むコメント
81+
}
82+
```
83+
84+
85+
#### PKZIP
86+
87+
PKZIP では複数のファイルを扱うため、他のものとは少し使い方が異なります。
88+
89+
```js
90+
var zip = new Zlib.Zip();
91+
// plainData1
92+
zip.addFile(plainData1, {
93+
filename: stringToByteArray('foo.txt')
94+
});
95+
zip.addFile(plainData2, {
96+
filename: stringToByteArray('bar.txt')
97+
});
98+
zip.addFile(plainData3, {
99+
filename: stringToByteArray('baz.txt')
100+
});
101+
var compressed = zip.compress();
102+
103+
function stringToByteArray(str) {
104+
var array = new (window.Uint8Array !== void 0 ? Uint8Array : Array)(str.length);
105+
var i;
106+
var il;
107+
108+
for (i = 0, il = str.length; i < il; ++i) {
109+
array[i] = str.charCodeAt(i) & 0xff;
70110
}
71111

112+
return array;
113+
}
114+
```
115+
116+
##### PKZIP Option
117+
118+
filename, comment, extraField は Typed Array が使用可能な場合は必ず Uint8Array を使用してください。
119+
120+
```js
121+
{
122+
filename: (Array.<number>|Uint8Array), // ファイル名
123+
comment: (Array.<number>|Uint8Array), // コメント
124+
extraField: (Array.<number>|Uint8Array), // その他の領域
125+
compress: boolean, // addFile メソッドを呼んだときに圧縮するか (通常は compress メソッドの呼び出し時に圧縮)
126+
compressionMethod: Zlib.Zip.CompressionMethod, // STORE or DEFLATE
127+
os: Zlib.Zip.OperatingSystem, // MSDOS or UNIX or MACINTOSH
128+
deflateOption: Object // see: ZLIB Option
129+
}
130+
```
72131

73132
### 伸張 (Decompress)
74133

@@ -78,21 +137,25 @@ zlib.js を用いて作成された GZIP の OS は、自動的に UNKNOWN に
78137

79138
#### ZLIB
80139

81-
var inflate = new Zlib.Inflate(compressed);
82-
var plain = inflate.decompress();
83-
140+
```js
141+
// compressed = Array.<number> or Uint8Array
142+
var inflate = new Zlib.Inflate(compressed);
143+
var plain = inflate.decompress();
144+
```
84145

85146
##### ZLIB Option
86147

87148
<code>Zlib.Inflate</code> の第二引数にオブジェクトを渡す事で伸張オプションを指定する事ができます。
88149

89-
{
90-
'index': number, // 入力バッファの開始位置
91-
'bufferSize': number, // 出力バッファの初期サイズ
92-
'bufferType': Zlib.Inflate.BufferType, // バッファの管理方法
93-
'resize': boolean, // 出力バッファのリサイズ
94-
'verify': boolean // 伸張結果の検証を行うか
95-
}
150+
```js
151+
{
152+
'index': number, // 入力バッファの開始位置
153+
'bufferSize': number, // 出力バッファの初期サイズ
154+
'bufferType': Zlib.Inflate.BufferType, // バッファの管理方法
155+
'resize': boolean, // 出力バッファのリサイズ
156+
'verify': boolean // 伸張結果の検証を行うか
157+
}
158+
```
96159

97160
<code>Zlib.Inflate.BufferType</code> は <code>ADAPTIVE</code>(default) か <code>BLOCK</code> を選択する事ができます。
98161

@@ -109,12 +172,29 @@ default は <code>false</code> です。
109172

110173
#### GZIP
111174

112-
var gunzip = new Zlib.Gunzip(compressed);
113-
var plain = gunzip.decompress();
175+
```js
176+
// compressed = Array.<number> or Uint8Array
177+
var gunzip = new Zlib.Gunzip(compressed);
178+
var plain = gunzip.decompress();
179+
```
114180

115181
Gunzip のオプションは現在ありません。
116182

117183

184+
#### PKZIP
185+
186+
PKZIP の構築と同様に複数ファイルを扱うため、他のものとは少し使い方が異なります。
187+
188+
```js
189+
// compressed = Array.<number> or Uint8Array
190+
var unzip = new Zlib.Unzip(compressed);
191+
var filenames = unzip.getFilenames();
192+
var plain = unzip.decompress(filenames[0]);
193+
```
194+
195+
Unzip のオプションは現在ありません。
196+
197+
118198
### Node.js
119199

120200
Node.js で使用する場合はユニットテストを参照してください。

0 commit comments

Comments
 (0)