apple-data-compression
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,2 +0,2 @@ | ||
var ADC = require( './adc' ) | ||
const ADC = require( './adc' ) | ||
@@ -6,8 +6,16 @@ // The sliding window buffer needs to be at least | ||
// The value of 128 was chosen as it's the next power of 2 from 67 | ||
const window = Buffer.allocUnsafeSlow( 65535 + 128, 0 ) | ||
// const window = Buffer.allocUnsafeSlow( 65535 + 128, 0 ) | ||
var windowOffset = 0 | ||
var windowSize = 65535 + 67 | ||
const window = new Uint8Array( windowSize ) | ||
window.fill( 0 ) | ||
function getWindow( position ) { | ||
return window[ ( position + windowOffset ) % windowSize ] | ||
} | ||
function slide( buffer, length ) { | ||
return buffer.copy( buffer, 0, length, buffer.length ) | ||
function setWindow( position, value ) { | ||
// NOTE: Guard against overrunning `Number.MAX_SAFE_INTEGER` | ||
// when decompressing large amounts of data; | ||
windowOffset = ( windowOffset % windowSize ) === 0 ? 0 : windowOffset | ||
return window[ ( position + windowOffset ) % windowSize ] = value | ||
} | ||
@@ -19,8 +27,15 @@ | ||
var data = Buffer.alloc( length, 0 ) | ||
var offset = windowSize - data.length | ||
slide( window, data.length ) | ||
// Advance position one byte, past the chunk length we read above | ||
position += 1 | ||
buffer.copy( data, 0, position + 1 ) | ||
buffer.copy( window, window.length - data.length, position + 1 ) | ||
windowOffset += length | ||
buffer.copy( data, 0, position ) | ||
for( var i = 0; i < length; i++ ) { | ||
setWindow( offset + i, buffer[ position++ ] ) | ||
} | ||
return data | ||
@@ -35,8 +50,8 @@ | ||
var data = Buffer.alloc( length, 0 ) | ||
var slidePosition = window.length - data.length | ||
var slidePosition = windowSize - data.length | ||
slide( window, data.length ) | ||
windowOffset += length | ||
for( var i = 0; i < length; i++ ) { | ||
data[i] = window[ slidePosition ] = window[ slidePosition - offset - 1 ] | ||
data[i] = setWindow( slidePosition, getWindow( slidePosition - offset - 1 ) ) | ||
slidePosition++ | ||
@@ -61,2 +76,4 @@ } | ||
windowOffset = 0 | ||
while( position < buffer.length ) { | ||
@@ -85,3 +102,2 @@ chunkType = ADC.getChunkType( buffer[ position ] ) | ||
decompress.slide = slide | ||
decompress.decode = decodeData | ||
@@ -88,0 +104,0 @@ decompress.runLength = decodeRunlength |
@@ -20,5 +20,3 @@ var ADC = require( './adc' ) | ||
this._window = Buffer.allocUnsafeSlow( 65535 + 128, 0 ) | ||
this._window.fill( 0 ) | ||
this._window = new Uint8Array( 65535 + 67 ) | ||
this._chunks = [] | ||
@@ -84,4 +82,3 @@ this._bytes = 0 | ||
this.push( Buffer.concat( chunks ) ) | ||
next() | ||
next( null, Buffer.concat( chunks ) ) | ||
@@ -88,0 +85,0 @@ }, |
{ | ||
"name": "apple-data-compression", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Apple Data Compression (ADC) Scheme", | ||
@@ -23,3 +23,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"mocha": "^3.5.3", | ||
"mocha": "^5.0.2", | ||
"nanobench": "^2.1.0" | ||
@@ -26,0 +26,0 @@ }, |
@@ -26,4 +26,19 @@ # Apple Data Compression (ADC) Scheme | ||
### Sync decompression | ||
```js | ||
adc.decompress( buffer ) => Buffer | ||
var result = adc.decompress( buffer ) | ||
``` | ||
### Streaming | ||
```js | ||
var transform = new adc.Decompressor() | ||
// OR var transform = adc.createDecompress() | ||
fs.createReadStream( filename ) | ||
.pipe( transform ) | ||
.on( 'data', ( chunk ) => { | ||
// ... | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10204
214
44