@chartiq/vinyl-tar

vinyl binding for tar-stream

Usage no npm install needed!

<script type="module">
  import chartiqVinylTar from 'https://cdn.skypack.dev/@chartiq/vinyl-tar';
</script>

README

@chartiq/vinyl-tar

Create a tarball from a vinyl stream. Extract a tarball as a vinyl stream source.

install

npm install --save @chartiq/vinyl-tar

pack

Creates a tarball from a vinyl stream. Acts like a vinyl adapter's destination stream.

const {pack} = require('@chartiq/vinyl-tar');
const fs = require('fs');
const through = require('through2');
const vfs = require('vinyl-fs');

vfs.src('**/*.txt')
    .pipe(through.obj((file, enc, next) => {
        const str = file.contents.toString();

        file.contents = Buffer.from(str.toUpperCase());

        next(null, file);
    }))
    .pipe(pack())
    .pipe(fs.createWriteStream('./uppercase.tar'));

extract

Emits each entry of the tarball as a vinyl object. Acts like a vinyl adapter's source stream.

const {extract} = require('@chartiq/vinyl-tar');
const fs = require('fs');
const through = require('through2');
const vfs = require('vinyl-fs');

fs.createReadStream('./files.tar')
    .pipe(extract())
    .pipe(through.obj((file, enc, next) => {
        if (file.stat.isBuffer() && file.stat.size > 1024) {
            next(null, file);
        } else {
            next(null);
        }
    }))
    .pipe(vfs.dest('files'));