Skip to content

Commit

Permalink
Merge branch 'release/0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuta Imaya committed Dec 18, 2012
2 parents 9f63495 + 05c562f commit e5c08f9
Show file tree
Hide file tree
Showing 18 changed files with 343 additions and 356 deletions.
60 changes: 28 additions & 32 deletions bin/deflate.min.js

Large diffs are not rendered by default.

59 changes: 28 additions & 31 deletions bin/gunzip.min.js

Large diffs are not rendered by default.

70 changes: 33 additions & 37 deletions bin/gzip.min.js

Large diffs are not rendered by default.

46 changes: 22 additions & 24 deletions bin/inflate.min.js

Large diffs are not rendered by default.

40 changes: 19 additions & 21 deletions bin/inflate_stream.min.js

Large diffs are not rendered by default.

111 changes: 54 additions & 57 deletions bin/node-zlib.js

Large diffs are not rendered by default.

85 changes: 41 additions & 44 deletions bin/zlib.min.js

Large diffs are not rendered by default.

108 changes: 52 additions & 56 deletions bin/zlib_and_gzip.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="project" default="all" >
<!--property name="level" value="SIMPLE_OPTIMIZATIONS"/-->
<!--
<property name="level" value="SIMPLE_OPTIMIZATIONS"/>
<property name="level" value="LIBRARY_OPTIMIZATIONS"/>
-->
<property name="level" value="PERFORMANCE_OPTIMIZATIONS"/>
<property name="src" value="./src"/>
<property name="def" value="./define"/>
<property name="vendor" value="./vendor"/>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "imaya <[email protected]>",
"name": "zlibjs",
"description": "zlib and gzip implementation in JavaScript",
"version": "0.1.1",
"version": "0.1.2",
"main": "./bin/node-zlib.js",
"homepage": "https://github.com/imaya/zlib.js",
"repository": {
Expand Down
25 changes: 13 additions & 12 deletions src/bitstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ Zlib.BitStream.prototype.writeBits = function(number, n, reverse) {
/** @type {number} loop counter. */
var i;

/**
* 32-bit 整数のビット順を逆にする
* @param {number} n 32-bit integer.
* @return {number} reversed 32-bit integer.
* @private
*/
function rev32_(n) {
return (Zlib.BitStream.ReverseTable[n & 0xFF] << 24) |
(Zlib.BitStream.ReverseTable[n >>> 8 & 0xFF] << 16) |
(Zlib.BitStream.ReverseTable[n >>> 16 & 0xFF] << 8) |
Zlib.BitStream.ReverseTable[n >>> 24 & 0xFF];
}

if (reverse && n > 1) {
number = n > 8 ?
rev32_(number) >> (32 - n) :
Expand Down Expand Up @@ -143,18 +156,6 @@ Zlib.BitStream.prototype.writeBits = function(number, n, reverse) {
this.index = index;
};

/**
* 32-bit 整数のビット順を逆にする
* @param {number} n 32-bit integer.
* @return {number} reversed 32-bit integer.
* @private
*/
function rev32_(n) {
return (Zlib.BitStream.ReverseTable[n & 0xFF] << 24) |
(Zlib.BitStream.ReverseTable[n >>> 8 & 0xFF] << 16) |
(Zlib.BitStream.ReverseTable[n >>> 16 & 0xFF] << 8) |
Zlib.BitStream.ReverseTable[n >>> 24 & 0xFF];
}

/**
* ストリームの終端処理を行う
Expand Down
6 changes: 3 additions & 3 deletions src/deflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ Zlib.Deflate.prototype.compress = function() {
}

// adler32
output[pos++] = (adler ) & 0xff;
output[pos++] = (adler >> 8) & 0xff;
output[pos++] = (adler >> 16) & 0xff;
output[pos++] = (adler >> 24) & 0xff;
output[pos++] = (adler >> 16) & 0xff;
output[pos++] = (adler >> 8) & 0xff;
output[pos++] = (adler ) & 0xff;

return output;
};
Expand Down
5 changes: 3 additions & 2 deletions src/inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ Zlib.Inflate.prototype.decompress = function() {

// verify adler-32
if (this.verify) {
adler32 =
adler32 = (
input[this.ip++] << 24 | input[this.ip++] << 16 |
input[this.ip++] << 8 | input[this.ip++];
input[this.ip++] << 8 | input[this.ip++]
) >>> 0;

if (adler32 !== Zlib.Adler32(buffer)) {
throw new Error('invalid adler-32 checksum');
Expand Down
23 changes: 12 additions & 11 deletions src/rawdeflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,19 +521,20 @@ Zlib.RawDeflate.prototype.fixedHuffman = function(dataArray, stream) {
* @param {!number} backwardDistance マッチ位置との距離.
* @constructor
*/
function Lz77Match(length, backwardDistance) {
Zlib.RawDeflate.Lz77Match = function(length, backwardDistance) {
/** @type {number} match length. */
this.length = length;
/** @type {number} backward distance. */
this.backwardDistance = backwardDistance;
}
};

/**
* 長さ符号テーブル.
* [コード, 拡張ビット, 拡張ビット長] の配列となっている.
* @const
* @type {!(Array.<number>|Uint32Array)}
*/
Lz77Match.LengthCodeTable = (function(table) {
Zlib.RawDeflate.Lz77Match.LengthCodeTable = (function(table) {
return USE_TYPEDARRAY ? new Uint32Array(table) : table;
})((function() {
/** @type {!Array} */
Expand Down Expand Up @@ -596,7 +597,7 @@ Lz77Match.LengthCodeTable = (function(table) {
* @return {!Array.<number>} コード、拡張ビット、拡張ビット長の配列.
* @private
*/
Lz77Match.prototype.getDistanceCode_ = function(dist) {
Zlib.RawDeflate.Lz77Match.prototype.getDistanceCode_ = function(dist) {
/** @type {!Array.<number>} distance code table. */
var r;

Expand Down Expand Up @@ -643,7 +644,7 @@ Lz77Match.prototype.getDistanceCode_ = function(dist) {
* [ CODE, EXTRA-BIT-LEN, EXTRA, CODE, EXTRA-BIT-LEN, EXTRA ]
* @return {!Array.<number>} LZ77 符号化 byte array.
*/
Lz77Match.prototype.toLz77Array = function() {
Zlib.RawDeflate.Lz77Match.prototype.toLz77Array = function() {
/** @type {number} */
var length = this.length;
/** @type {number} */
Expand All @@ -656,7 +657,7 @@ Lz77Match.prototype.toLz77Array = function() {
var code;

// length
code = Lz77Match.LengthCodeTable[length];
code = Zlib.RawDeflate.Lz77Match.LengthCodeTable[length];
codeArray[pos++] = code & 0xffff;
codeArray[pos++] = (code >> 16) & 0xff;
codeArray[pos++] = code >> 24;
Expand Down Expand Up @@ -692,9 +693,9 @@ Zlib.RawDeflate.prototype.lz77 = function(dataArray) {
var windowSize = Zlib.RawDeflate.WindowSize;
/** @type {Array.<Array.<number>>} match list */
var matchList;
/** @type {Lz77Match} longest match */
/** @type {Zlib.RawDeflate.Lz77Match} longest match */
var longestMatch;
/** @type {Lz77Match} previous longest match */
/** @type {Zlib.RawDeflate.Lz77Match} previous longest match */
var prevMatch;
/** @type {!(Array.<number>|Uint16Array)} lz77 buffer */
var lz77buf = USE_TYPEDARRAY ?
Expand All @@ -721,7 +722,7 @@ Zlib.RawDeflate.prototype.lz77 = function(dataArray) {

/**
* マッチデータの書き込み
* @param {Lz77Match} match LZ77 Match data.
* @param {Zlib.RawDeflate.Lz77Match} match LZ77 Match data.
* @param {!number} offset スキップ開始位置(相対指定).
* @private
*/
Expand Down Expand Up @@ -832,7 +833,7 @@ Zlib.RawDeflate.prototype.lz77 = function(dataArray) {
* @param {!Object} data plain data byte array.
* @param {!number} position plain data byte array position.
* @param {!Array.<number>} matchList 候補となる位置の配列.
* @return {!Lz77Match} 最長かつ最短距離のマッチオブジェクト.
* @return {!Zlib.RawDeflate.Lz77Match} 最長かつ最短距離のマッチオブジェクト.
* @private
*/
Zlib.RawDeflate.prototype.searchLongestMatch_ =
Expand Down Expand Up @@ -877,7 +878,7 @@ function(data, position, matchList) {
}
}

return new Lz77Match(matchMax, position - currentMatch);
return new Zlib.RawDeflate.Lz77Match(matchMax, position - currentMatch);
};

/**
Expand Down
42 changes: 20 additions & 22 deletions src/rawinflate_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ Zlib.RawInflateStream.prototype.readBlockHeader = function() {

this.status = Zlib.RawInflateStream.Status.BLOCK_HEADER_START;

save(this);
this.save_();
if ((hdr = this.readBits(3)) < 0) {
restore(this);
this.restore_();
return -1;
}

Expand Down Expand Up @@ -546,25 +546,23 @@ Zlib.RawInflateStream.prototype.parseFixedHuffmanBlock = function() {

/**
* オブジェクトのコンテキストを別のプロパティに退避する.
* @param {Zlib.RawInflateStream} target 対象オブジェクト.
* @private
*/
function save(target) {
target.ip_ = target.ip;
target.bitsbuflen_ = target.bitsbuflen;
target.bitsbuf_ = target.bitsbuf;
}
Zlib.RawInflateStream.prototype.save_ = function() {
this.ip_ = this.ip;
this.bitsbuflen_ = this.bitsbuflen;
this.bitsbuf_ = this.bitsbuf;
};

/**
* 別のプロパティに退避したコンテキストを復元する.
* @param {Zlib.RawInflateStream} target 対象オブジェクト.
* @private
*/
function restore(target) {
target.ip = target.ip_;
target.bitsbuflen = target.bitsbuflen_;
target.bitsbuf = target.bitsbuf_;
}
Zlib.RawInflateStream.prototype.restore_ = function() {
this.ip = this.ip_;
this.bitsbuflen = this.bitsbuflen_;
this.bitsbuf = this.bitsbuf_;
};

/**
* parse dynamic huffman block.
Expand Down Expand Up @@ -592,19 +590,19 @@ Zlib.RawInflateStream.prototype.parseDynamicHuffmanBlock = function() {

this.status = Zlib.RawInflateStream.Status.BLOCK_BODY_START;

save(this);
this.save_();
hlit = this.readBits(5) + 257;
hdist = this.readBits(5) + 1;
hclen = this.readBits(4) + 4;
if (hlit < 0 || hdist < 0 || hclen < 0) {
restore(this);
this.restore_();
return -1;
}

try {
parseDynamicHuffmanBlockImpl.call(this);
} catch(e) {
restore(this);
this.restore_();
return -1;
}

Expand Down Expand Up @@ -713,12 +711,12 @@ Zlib.RawInflateStream.prototype.decodeHuffman = function() {
this.status = Zlib.RawInflateStream.Status.DECODE_BLOCK_START;

while (true) {
save(this);
this.save_();

code = this.readCodeByTable(litlen);
if (code < 0) {
this.op = op;
restore(this);
this.restore_();
return -1;
}

Expand All @@ -744,7 +742,7 @@ Zlib.RawInflateStream.prototype.decodeHuffman = function() {
bits = this.readBits(Zlib.RawInflateStream.LengthExtraTable[ti]);
if (bits < 0) {
this.op = op;
restore(this);
this.restore_();
return -1;
}
codeLength += bits;
Expand All @@ -754,15 +752,15 @@ Zlib.RawInflateStream.prototype.decodeHuffman = function() {
code = this.readCodeByTable(dist);
if (code < 0) {
this.op = op;
restore(this);
this.restore_();
return -1;
}
codeDist = Zlib.RawInflateStream.DistCodeTable[code];
if (Zlib.RawInflateStream.DistExtraTable[code] > 0) {
bits = this.readBits(Zlib.RawInflateStream.DistExtraTable[code]);
if (bits < 0) {
this.op = op;
restore(this);
this.restore_();
return -1;
}
codeDist += bits;
Expand Down
4 changes: 3 additions & 1 deletion test/browser-plain-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ function inflateTest(mode, testData, compressionType) {
console.log("deflated data size:", deflate.length);

// inflate
inflate = (new Zlib.Inflate(deflate)).decompress();
inflate = (new Zlib.Inflate(deflate, {
verify: true
})).decompress();
console.log("inflated data size:", inflate.length)

// assertion
Expand Down
8 changes: 7 additions & 1 deletion test/browser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ buster.testCase(

var inflator = new Zlib.Inflate(decodedData, {
bufferType: Zlib.Inflate.BufferType.BLOCK,
bufferSize: 41152
bufferSize: 41152,
verify: true
});
var inflated = inflator.decompress();

Expand Down Expand Up @@ -254,6 +255,11 @@ function inflateTest(mode, testData, compressionType, inflateOption) {
console.log("deflated data size:", deflate.length);

// inflate
if (inflateOption) {
inflateOption.verify = true;
} else {
inflateOption = {verify: true};
}
inflate = (new Zlib.Inflate(deflate, inflateOption)).decompress();
console.log("inflated data size:", inflate.length)

Expand Down
Binary file modified vendor/google-closure-compiler/compiler.jar
Binary file not shown.

0 comments on commit e5c08f9

Please sign in to comment.