Skip to content

Commit

Permalink
Update the Buffer APIs (#98)
Browse files Browse the repository at this point in the history
* Use Buffer.alloc/Buffer.from instead of "new Buffer"
* Remove the 'noAssert' parameter from the write calls
  This got removed with nodejs/node#18395

Fixes #91
  • Loading branch information
ankon committed Jun 22, 2020
1 parent 29ecbd1 commit 76f347f
Show file tree
Hide file tree
Showing 20 changed files with 5,730 additions and 5,685 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -37,9 +37,9 @@ var LZ4 = require('lz4')
var data = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
data += data
// LZ4 can only work on Buffers
var input = new Buffer(data)
var input = Buffer.from(data)
// Initialize the output buffer to its maximum length based on the input data
var output = new Buffer( LZ4.encodeBound(input.length) )
var output = Buffer.alloc( LZ4.encodeBound(input.length) )
// block compression (no archive format)
var compressedSize = LZ4.encodeBlock(input, output)
Expand All @@ -49,7 +49,7 @@ output = output.slice(0, compressedSize)
console.log( "compressed data", output )
// block decompression (no archive format)
var uncompressed = new Buffer(input.length)
var uncompressed = Buffer.alloc(input.length)
var uncompressedSize = LZ4.decodeBlock(output, uncompressed)
uncompressed = uncompressed.slice(0, uncompressedSize)
Expand Down
6 changes: 3 additions & 3 deletions benchmark/bench.js
Expand Up @@ -9,10 +9,10 @@ console.log('Input file:', inputFileName)

var input = fs.readFileSync(inputFileName)
var outputMaxSize = lz4.encodeBound(input.length)
var output = new Buffer(outputMaxSize)
var output = Buffer.alloc(outputMaxSize)

var decoded = new Buffer(input.length)
var encoded = new Buffer(outputMaxSize)
var decoded = Buffer.alloc(input.length)
var encoded = Buffer.alloc(outputMaxSize)
var n = lz4.encodeBlock(input, encoded)
encoded = encoded.slice(0, n)

Expand Down

0 comments on commit 76f347f

Please sign in to comment.