Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: coderaiser/node-jag
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5565288ea7c70fc606b37e34675c8f3c964a9493
Choose a base ref
...
head repository: coderaiser/node-jag
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 20d161cef32f5f405d671bf23079c3cad2e591e4
Choose a head ref
  • 9 commits
  • 5 files changed
  • 1 contributor

Commits on Apr 21, 2017

  1. docs(readme) add bizzy

    coderaiser committed Apr 21, 2017
    Copy the full SHA
    7ff44cf View commit details

Commits on Jun 15, 2017

  1. Copy the full SHA
    5867890 View commit details
  2. Copy the full SHA
    ec2d19f View commit details

Commits on Jul 14, 2017

  1. docs(license) 2017

    coderaiser committed Jul 14, 2017
    Copy the full SHA
    3ae9be3 View commit details
  2. Copy the full SHA
    7a115e8 View commit details
  3. Copy the full SHA
    f370fe0 View commit details
  4. chore(package) v2.0.0

    coderaiser committed Jul 14, 2017
    Copy the full SHA
    e71341f View commit details

Commits on Aug 31, 2017

  1. Copy the full SHA
    dc95284 View commit details
  2. chore(package) v2.0.1

    coderaiser committed Aug 31, 2017
    Copy the full SHA
    20d161c View commit details
Showing with 89 additions and 79 deletions.
  1. +15 −0 ChangeLog
  2. +1 −1 LICENSE
  3. +6 −5 README.md
  4. +60 −71 lib/jag.js
  5. +7 −2 package.json
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2017.08.31, v2.0.1

feature:
- (package) tar v4.0.1


2017.07.14, v2.0.0

feature:
- (package) tar v3.1.5
- (jag) drop support of node version < 4
- (package) nyc v11.0.2
- (package) eslint v4.0.0


2016.11.09, v1.0.14

feature:
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 coderaiser
Copyright (c) 2014-2017 coderaiser

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,18 +10,19 @@ Pack files and folders with tar and gzip. Use [jaguar](https://github.com/codera
## Hot to use?

```js
var jag = require('jag'),
fn = function(error) {
if (error)
console.error(error.message);
};
const jag = require('jag');
const fn = function(error) {
if (error)
console.error(error.message);
};

jag.pack('/tmp/lib', '/tmp/1/lib', fn); /* extenstion would be added */
jag.unpack('/tmp/lib.tar.gz', '/tmp/lib', fn);
```
## Related

- [Jaguar](https://github.com/coderaiser/node-jaguar "Jaguar") - Pack and extract .tar.gz archives with emitter.
- [Bizzy](https://github.com/coderaiser/node-bizzy "Bizzy") - Pack and extract .tar.bz2 archives with emitter.
- [OneZip](https://github.com/coderaiser/node-onezip "OneZip") - Pack and extract zip archives with emitter.
- [Tar-to-zip](https://github.com/coderaiser/node-tar-to-zip "tar-to-zip") - Convert tar and tar.gz archives to zip.

131 changes: 60 additions & 71 deletions lib/jag.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,96 @@
'use strict';

var path = require('path'),
fs = require('fs'),
zlib = require('zlib'),

tar = require('tar'),
fstream = require('fstream'),

check = require('checkup'),
pipe = require('pipe-io/legacy'),
files = require('files-io');
const path = require('path'),
const fs = require('fs'),
const zlib = require('zlib'),

const tar = require('tar'),
const fstream = require('fstream'),

exports.pack = function(from, to, callback) {
const check = require('checkup'),
const pipe = require('pipe-io/legacy'),
const files = require('files-io');

exports.pack = (from, to, callback) => {
check
.type('callback', callback, 'function')
.check({
to: to,
from: from
to,
from,
});

isDir(from, function(is) {
var dir, name,

optionsDir = { path: from, type: 'Directory' },
optionsTar = { noProprietary: true },

streamDir,
streamTar,
streamZip = zlib.createGzip(),
streamFile,

isStr = typeof to === 'string',
options = {
gzip: true
};
isDir(from, (is) => {
const optionsDir = { path: from, type: 'Directory' };
const optionsTar = { noProprietary: true };
const streamZip = zlib.createGzip();
const isStr = typeof to === 'string';
const options = {
gzip: true
};

if (!is) {
files.pipe(from, to, options, callback);
return files.pipe(from, to, options, callback);

const streamDir = fstream.Reader(optionsDir);
const streamTar = tar.Pack(optionsTar);

let streamFile;
if (!isStr) {
streamFile = to;
} else {
streamDir = fstream.Reader(optionsDir);
streamTar = tar.Pack(optionsTar);

if (!isStr) {
streamFile = to;
} else {
dir = path.dirname(to);
name = path.basename(to, '.gz');

if (dir !== '/')
dir += path.sep;

to = dir + name + '.tar.gz';

streamFile = fs.createWriteStream(to);
}
const dir = path.dirname(to);
const name = path.basename(to, '.gz');

pipe([
streamDir,
streamTar,
streamZip,
streamFile
], callback);
if (dir !== '/')
dir += path.sep;

const to = dir + name + '.tar.gz';

streamFile = fs.createWriteStream(to);
}

pipe([
streamDir,
streamTar,
streamZip,
streamFile
], callback);
});
};

exports.unpack = function(from, to, callback) {
var write, error,
isStr = typeof from === 'string',
isGz = /\.gz$/.test(from),
isTarGz = /\.tar\.gz$/.test(from),

options = {
gunzip : true
};
exports.unpack = (from, to, callback) => {
const isStr = typeof from === 'string';
const isGz = /\.gz$/.test(from);
const isTarGz = /\.tar\.gz$/.test(from);

const options = {
gunzip: true
};

check
.type('callback', callback, 'function')
.check({
to: to,
from: from
to,
from,
});

let write;
if (isTarGz)
write = tar.Extract({ path: path.dirname(to) });
else if (!isStr || isGz)
write = to;
else
error = Error('wrong file type: can be ".gz" or ".tar.gz"!');

if (error)
callback(error);
else
files.pipe(from, write, options, callback);
return callback(Error('wrong file type: can be ".gz" or ".tar.gz"!'));

files.pipe(from, write, options, callback);
};

function isDir(name, callback) {
fs.stat(name, function(error, stat) {
var isDir;

fs.stat(name, (error, stat) => {
if (!error)
isDir = stat.isDirectory();

callback(isDir);
});
}

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{
"name": "jag",
"version": "1.0.14",
"version": "2.0.1",
"description": "pack files and folders with tar and gzip",
"main": "lib/jag.js",
"dependencies": {
"checkup": "~1.3.0",
"files-io": "~1.2.1",
"fstream": "~1.0.3",
"pipe-io": "^2.0.1",
"tar": "~2.2.0"
"tar": "^4.0.1",
"eslint": "^4.0.0",
"nyc": "^11.0.2"
},
"devDependencies": {},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},