Created
June 30, 2019 06:16
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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