Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created June 30, 2019 06:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save isaacs/87bb3c473cf6ccf47c302557b9f14b95 to your computer and use it in GitHub Desktop.
const tar = require('tar')
const {writeFileSync} = require('fs')
const {resolve} = require('path')
const {spawnSync} = require('child_process')
const mkdirp = require('mkdirp')
const $ = (...args) => {
const res = spawnSync('tar', args, { stdio: [0, 1, 2 ] }).status
console.log(res ? `ERROR=${res}` : 'OK')
}
console.log(`node-tar v${require('tar/package.json').version}`)
console.log('system tar is:')
$('--version')
const longName = 'very long file name a s dd f ' +
'df sdfsdfsdfsdfsdffffffff~fffffsdddddddddddd' +
'dddddddddddddddssssssssssssssssss.xml'
const cwd = resolve('working-dir')
mkdirp.sync(cwd)
writeFileSync(cwd + '/' + longName, '{"json":"is basically xml right?"}')
const sync = true
const gzip = true
const file = 'longname-archive-node-tar.tgz'
const sfile = 'longname-archive-system-tar.tgz'
console.log('create with node-tar')
tar.c({ sync, gzip, file, cwd }, [longName])
console.log('create with system tar')
$('czf', sfile, '-C', cwd, longName)
console.log('created with node tar, list with node-tar')
const onentry = entry => console.log(entry.path)
tar.t({ sync, file, onentry })
console.log('created with node-tar, list with system-tar')
$('tf', file)
console.log('created with system tar, list with node-tar')
tar.t({ sync, file: sfile, onentry })
console.log('created with system tar, list with system-tar')
$('tf', sfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment