Skip to content

Commit

Permalink
Bump v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zhipeng-jia committed Sep 1, 2016
1 parent 33e4b95 commit 77eeef4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "snappyjs",
"main": "./dist/snappyjs.js",
"version": "0.4.1",
"version": "0.5.0",
"homepage": "https://github.com/zhipeng-jia/snappyjs",
"authors": [
"Zhipeng Jia <[email protected]>"
Expand Down
38 changes: 29 additions & 9 deletions dist/snappyjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* snappyjs:
* license: MIT
* author: Zhipeng Jia
* version: 0.4.1
* version: 0.5.0
*
* This header is generated by licensify (https://github.com/twada/licensify)
*/
Expand Down Expand Up @@ -75,6 +75,10 @@ function isNode () {

var is_node = isNode()

function isUint8Array (object) {
return object instanceof Uint8Array && (!is_node || !Buffer.isBuffer(object))
}

function isArrayBuffer (object) {
return object instanceof ArrayBuffer
}
Expand All @@ -89,12 +93,17 @@ function isBuffer (object) {
var SnappyDecompressor = require('./snappy_decompressor').SnappyDecompressor
var SnappyCompressor = require('./snappy_compressor').SnappyCompressor

var TYPE_ERROR_MSG = 'Argument compressed must be type of ArrayBuffer, Buffer, or Uint8Array'

function uncompress (compressed) {
if (!isArrayBuffer(compressed) && !isBuffer(compressed)) {
throw new TypeError('Argument compressed must be type of ArrayBuffer or Buffer')
if (!isUint8Array(compressed) && !isArrayBuffer(compressed) && !isBuffer(compressed)) {
throw new TypeError(TYPE_ERROR_MSG)
}
var uint8_mode = false
var array_buffer_mode = false
if (isArrayBuffer(compressed)) {
if (isUint8Array(compressed)) {
uint8_mode = true
} else if (isArrayBuffer(compressed)) {
array_buffer_mode = true
compressed = new Uint8Array(compressed)
}
Expand All @@ -104,7 +113,12 @@ function uncompress (compressed) {
throw new Error('Invalid Snappy bitstream')
}
var uncompressed, uncompressed_view
if (array_buffer_mode) {
if (uint8_mode) {
uncompressed = new Uint8Array(length)
if (!decompressor.uncompressToBuffer(uncompressed)) {
throw new Error('Invalid Snappy bitstream')
}
} else if (array_buffer_mode) {
uncompressed = new ArrayBuffer(length)
uncompressed_view = new Uint8Array(uncompressed)
if (!decompressor.uncompressToBuffer(uncompressed_view)) {
Expand All @@ -120,19 +134,25 @@ function uncompress (compressed) {
}

function compress (uncompressed) {
if (!isArrayBuffer(uncompressed) && !isBuffer(uncompressed)) {
throw new TypeError('Argument uncompressed must be type of ArrayBuffer or Buffer')
if (!isUint8Array(uncompressed) && !isArrayBuffer(uncompressed) && !isBuffer(uncompressed)) {
throw new TypeError(TYPE_ERROR_MSG)
}
var uint8_mode = false
var array_buffer_mode = false
if (isArrayBuffer(uncompressed)) {
if (isUint8Array(compressed)) {
uint8_mode = true
} else if (isArrayBuffer(uncompressed)) {
array_buffer_mode = true
uncompressed = new Uint8Array(uncompressed)
}
var compressor = new SnappyCompressor(uncompressed)
var max_length = compressor.maxCompressedLength()
var compressed, compressed_view
var length
if (array_buffer_mode) {
if (uint8_mode) {
compressed = new Uint8Array(max_length)
length = compressor.compressToBuffer(compressed)
} else if (array_buffer_mode) {
compressed = new ArrayBuffer(max_length)
compressed_view = new Uint8Array(compressed)
length = compressor.compressToBuffer(compressed_view)
Expand Down
4 changes: 2 additions & 2 deletions dist/snappyjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snappyjs",
"version": "0.4.1",
"version": "0.5.0",
"description": "JavaScript implementation of Google's Snappy compression library",
"repository": "zhipeng-jia/snappyjs",
"main": "index.js",
Expand Down

0 comments on commit 77eeef4

Please sign in to comment.