Skip to content

Commit

Permalink
Use Buffer.from instead of 'new Buffer'
Browse files Browse the repository at this point in the history
Buffer() constructor is deprecated.

Refs: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor

Fix #175

(Edited by @isaacs to update tests as well as lib)
  • Loading branch information
ChALkeR authored and isaacs committed Mar 20, 2018
1 parent c8152e8 commit 4513e3b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Entry = require('./read-entry.js')
const Pax = require('./pax.js')
const zlib = require('minizlib')

const gzipHeader = new Buffer([0x1f, 0x8b])
const gzipHeader = Buffer.from([0x1f, 0x8b])
const STATE = Symbol('state')
const WRITEENTRY = Symbol('writeEntry')
const READENTRY = Symbol('readEntry')
Expand Down
18 changes: 9 additions & 9 deletions test/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const t = require('tap')
const Header = require('../lib/header.js')

t.test('ustar format', t => {
const buf = new Buffer(
const buf = Buffer.from(
'666f6f2e74787400000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
Expand Down Expand Up @@ -63,7 +63,7 @@ t.test('ustar format', t => {
})

t.test('xstar format', t => {
const buf = new Buffer(
const buf = Buffer.from(
'666f6f2e74787400000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
Expand Down Expand Up @@ -130,7 +130,7 @@ t.test('prefix handling', t => {
t.plan(4)

t.test('no times', t => {
const buf = new Buffer(
const buf = Buffer.from(
'666f6f2e74787400000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
Expand Down Expand Up @@ -202,7 +202,7 @@ t.test('prefix handling', t => {
})

t.test('a/c times, use shorter prefix field', t => {
const buf = new Buffer(
const buf = Buffer.from(
'652f702f2d2f702f612f742f682f666f6f2e7478740000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
Expand Down Expand Up @@ -274,7 +274,7 @@ t.test('prefix handling', t => {
})

t.test('hella long basename', t => {
const buf = new Buffer(
const buf = Buffer.from(
'6c6f6e672d66696c652d6c6f6e672d66696c652d6c6f6e672d66696c652d6c6f' +
'6e672d66696c652d6c6f6e672d66696c652d6c6f6e672d66696c652d6c6f6e67' +
'2d66696c652d6c6f6e672d66696c652d6c6f6e672d66696c652d6c6f6e672d66' +
Expand Down Expand Up @@ -331,7 +331,7 @@ t.test('prefix handling', t => {
})

t.test('long basename, long dirname', t => {
const buf = new Buffer(
const buf = Buffer.from(
'6c6f6e672d6469726e616d652d6c6f6e672d6469726e616d652d6c6f6e672d64' +
'69726e616d652d6c6f6e672d6469726e616d652d6c6f6e672d6469726e616d65' +
'2d6c6f6e672d6469726e616d652d6c6f6e672d6469726e616d652d6c6f6e672d' +
Expand Down Expand Up @@ -424,7 +424,7 @@ t.test('null block', t => {
})

t.test('unknown type', t => {
const h = new Header(new Buffer(
const h = new Header(Buffer.from(
'666f6f2e74787400000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
Expand All @@ -449,7 +449,7 @@ t.test('unknown type', t => {
})

t.test('dir as file with trailing /', t => {
const b = new Buffer(
const b = Buffer.from(
'782f792f00000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
Expand Down Expand Up @@ -534,7 +534,7 @@ t.test('big numbers', t => {
})

t.test('dir with long body', t => {
const b = new Buffer(
const b = Buffer.from(
'7061636b6167652f76656e646f72000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
Expand Down
2 changes: 1 addition & 1 deletion test/large-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ t.test('parse', t => {
])
t.plan(cases.size)
cases.forEach((value, hex) =>
t.equal(parse(new Buffer(hex, 'hex')), value))
t.equal(parse(Buffer.from(hex, 'hex')), value))
})

t.test('encode', t => {
Expand Down
2 changes: 1 addition & 1 deletion test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ t.test('truncated input', t => {
const warnings = []
const p = new Parse({ onwarn: message => warnings.push(message) })
p.write(data)
p.end(new Buffer('not a full block'))
p.end(Buffer.from('not a full block'))
t.same(warnings, [
'Truncated input (needed 512 more bytes, only 16 available)'
])
Expand Down
4 changes: 2 additions & 2 deletions test/pax.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ t.test('create a pax', t => {

// console.log(p.encode().toString('hex').split('').reduce((s,c)=>{if(s[s.length-1].length<64)s[s.length-1]+=c;else s.push(c);return s},['']))

const buf = new Buffer(
const buf = Buffer.from(
// pax entry header
'5061784865616465722f666f6f2e747874000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
Expand Down Expand Up @@ -77,7 +77,7 @@ t.test('tiny pax', t => {
// console.log(actual.toString('hex').split('').reduce((s,c)=>{if(s[s.length-1].length<64)s[s.length-1]+=c;else s.push(c);return s},['']))
// return Promise.resolve()

const buf = new Buffer(
const buf = Buffer.from(
// header
'5061784865616465722f61620000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
Expand Down
4 changes: 2 additions & 2 deletions test/unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ t.test('transmute chars on windows', t => {
t.afterEach(cb => rimraf(dir, cb))

const hex = 'ef80bcef81bcef80beef80bfef80ba2e747874'
const uglyName = new Buffer(hex, 'hex').toString()
const uglyName = Buffer.from(hex, 'hex').toString()
const ugly = path.resolve(dir, uglyName)

const check = t => {
Expand Down Expand Up @@ -1782,7 +1782,7 @@ t.test('safely transmute chars on windows with absolutes', t => {
])

const hex = 'ef80bcef81bcef80beef80bfef80ba2e747874'
const uglyName = new Buffer(hex, 'hex').toString()
const uglyName = Buffer.from(hex, 'hex').toString()
const uglyPath = 'c:/x/y/z/' + uglyName

const u = new Unpack({
Expand Down
6 changes: 3 additions & 3 deletions test/write-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ t.test('win32 <|>? in paths', {
skip: isWindows && 'do not create annoying junk on windows systems'
}, t => {
const file = path.resolve(fixtures, '<|>?.txt')
const uglyName = new Buffer('ef80bcef81bcef80beef80bf2e747874', 'hex').toString()
const uglyName = Buffer.from('ef80bcef81bcef80beef80bf2e747874', 'hex').toString()
const ugly = path.resolve(fixtures, uglyName)
t.teardown(_ => {
rimraf.sync(file)
Expand Down Expand Up @@ -1074,7 +1074,7 @@ t.test('write entry from read entry', t => {
let wetEnded = false
wet.on('end', _ => wetEnded = true)
t.equal(wetEnded, false)
readEntry.end(new Buffer(new Array(513).join('@')))
readEntry.end(Buffer.from(new Array(513).join('@')))
t.equal(wetEnded, true)
const res = Buffer.concat(out)
t.equal(res.length, 1024)
Expand All @@ -1089,7 +1089,7 @@ t.test('write entry from read entry', t => {
size: '1'
}))
const wet = new WriteEntry.Tar(readEntry)
t.throws(_ => wet.write(new Buffer(new Array(1024).join('x'))))
t.throws(_ => wet.write(Buffer.from(new Array(1024).join('x'))))
t.end()
})

Expand Down

0 comments on commit 4513e3b

Please sign in to comment.