Skip to content

Commit bdbad1e

Browse files
committedApr 6, 2018
update dependencies and devDependencies
Highlight: update @shinnn/eslint-config and follow its rules, for exmaple tab indent
1 parent b5ec159 commit bdbad1e

File tree

6 files changed

+4940
-3712
lines changed

6 files changed

+4940
-3712
lines changed
 

‎.editorconfig

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ root = true
33
[*]
44
charset = utf-8
55
end_of_line = lf
6-
indent_style = space
7-
indent_size = 2
6+
indent_style = tab
7+
tab_width = 2
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

11+
[*.{md,yml}]
12+
indent_style = space
13+
1114
[*.md]
1215
trim_trailing_whitespace = false

‎LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ISC License (ISC)
2-
Copyright 2017 Shinnosuke Watanabe
2+
Copyright 2017 - 2018 Shinnosuke Watanabe
33

44
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
55

‎index.js

+166-167
Original file line numberDiff line numberDiff line change
@@ -22,177 +22,176 @@ const Transform = streamLib.Transform;
2222

2323
const FILE_PATH_ERROR = 'Expected a file path to be compressed as an archive';
2424
const TAR_PATH_ERROR = 'Expected a file path where an archive file will be created';
25-
const TAR_TRANSFORM_ERROR = '`tarTransform` option must be a transform stream ' +
26-
'that modifies the tar archive before writing';
25+
const TAR_TRANSFORM_ERROR = '`tarTransform` option must be a transform stream that modifies the tar archive before writing';
2726
const MAP_STREAM_ERROR = 'The function passed to `mapStream` option must return a stream';
2827

2928
const unsupportedOptions = [
30-
'entries',
31-
'filter',
32-
'ignore',
33-
'strip'
29+
'entries',
30+
'filter',
31+
'ignore',
32+
'strip'
3433
];
3534

3635
module.exports = function fileToTar(filePath, tarPath, options) {
37-
return new Observable(observer => {
38-
if (typeof filePath !== 'string') {
39-
throw new TypeError(`${FILE_PATH_ERROR}, but got a non-string value ${inspectWithKind(filePath)}.`);
40-
}
41-
42-
if (filePath.length === 0) {
43-
throw new Error(`${FILE_PATH_ERROR}, but got '' (empty string).`);
44-
}
45-
46-
if (typeof tarPath !== 'string') {
47-
throw new TypeError(`${TAR_PATH_ERROR}, but got a non-string value ${inspectWithKind(tarPath)}.`);
48-
}
49-
50-
if (tarPath.length === 0) {
51-
throw new Error(`${TAR_PATH_ERROR}, but got '' (empty string).`);
52-
}
53-
54-
const absoluteFilePath = resolve(filePath);
55-
const absoluteTarPath = resolve(tarPath);
56-
const dirPath = dirname(absoluteFilePath);
57-
58-
if (absoluteFilePath === absoluteTarPath) {
59-
throw new Error(`Source file path must be different from the archive path. Both were specified to ${
60-
absoluteFilePath
61-
}.`);
62-
}
63-
64-
if (options !== undefined) {
65-
if (!isPlainObj(options)) {
66-
throw new TypeError(`Expected a plain object to set file-to-tar options, but got ${
67-
inspectWithKind(options)
68-
}.`);
69-
}
70-
} else {
71-
options = {};
72-
}
73-
74-
for (const optionName of unsupportedOptions) {
75-
const val = options[optionName];
76-
77-
if (val !== undefined) {
78-
throw new Error(`file-to-tar doesn't support \`${optionName}\` option, but ${
79-
inspectWithKind(val)
80-
} was provided.`);
81-
}
82-
}
83-
84-
if (options.tarTransform !== undefined) {
85-
if (!isStream(options.tarTransform)) {
86-
throw new TypeError(`${TAR_TRANSFORM_ERROR}, but got a non-stream value ${
87-
inspectWithKind(options.tarTransform)
88-
}.`);
89-
}
90-
91-
if (!isStream.transform(options.tarTransform)) {
92-
throw new TypeError(`${TAR_TRANSFORM_ERROR}, but got a ${
93-
['duplex', 'writable', 'readable'].find(type => isStream[type](options.tarTransform))
94-
} stream instead.`);
95-
}
96-
}
97-
98-
let cancel;
99-
100-
lstat(absoluteFilePath, (lstatErr, stat) => {
101-
if (lstatErr) {
102-
observer.error(lstatErr);
103-
return;
104-
}
105-
106-
if (!stat.isFile()) {
107-
observer.error(new Error(`Expected ${absoluteFilePath} to be a file path, but it was a ${
108-
stat.isDirectory() ? 'directory' : 'symbolic link'
109-
}.`));
110-
111-
return;
112-
}
113-
114-
let firstWriteFailed = false;
115-
116-
const firstWriteStream = fs.createWriteStream(tarPath, options).on('error', err => {
117-
if (err.code === 'EISDIR') {
118-
err.message = `Tried to write an archive file to ${absoluteTarPath}, but a directory already exists there.`;
119-
observer.error(err);
120-
121-
return;
122-
}
123-
124-
firstWriteFailed = true;
125-
});
126-
127-
mkdirp(dirname(tarPath), Object.assign({fs}, options), mkdirpErr => {
128-
if (mkdirpErr) {
129-
observer.error(mkdirpErr);
130-
return;
131-
}
132-
133-
const packStream = pack(dirPath, Object.assign({fs}, options, {
134-
entries: [basename(filePath)],
135-
map(header) {
136-
if (options.map) {
137-
header = options.map(header);
138-
}
139-
140-
return header;
141-
},
142-
mapStream(fileStream, header) {
143-
const newStream = options.mapStream ? options.mapStream(fileStream, header) : fileStream;
144-
145-
if (!isStream.readable(newStream)) {
146-
packStream.emit('error', new TypeError(`${MAP_STREAM_ERROR}${
147-
isStream(newStream) ?
148-
' that is readable, but returned a non-readable stream' :
149-
`, but returned a non-stream value ${inspectWithKind(newStream)}`
150-
}.`));
151-
152-
return new PassThrough();
153-
}
154-
155-
let bytes = 0;
156-
157-
observer.next({bytes, header});
158-
159-
return newStream.pipe(new Transform({
160-
transform(chunk, encoding, cb) {
161-
bytes += chunk.length;
162-
163-
observer.next({bytes, header});
164-
cb(null, chunk);
165-
}
166-
}));
167-
}
168-
}));
169-
170-
function getDest() {
171-
return firstWriteFailed ? fs.createWriteStream(tarPath, options) : firstWriteStream;
172-
}
173-
174-
cancel = cancelablePump(options.tarTransform ? [
175-
packStream,
176-
options.tarTransform,
177-
getDest()
178-
] : [
179-
packStream,
180-
getDest()
181-
], err => {
182-
if (err) {
183-
observer.error(err);
184-
return;
185-
}
186-
187-
observer.complete();
188-
});
189-
});
190-
});
191-
192-
return function cancelCompression() {
193-
if (cancel) {
194-
cancel();
195-
}
196-
};
197-
});
36+
return new Observable(observer => {
37+
if (typeof filePath !== 'string') {
38+
throw new TypeError(`${FILE_PATH_ERROR}, but got a non-string value ${inspectWithKind(filePath)}.`);
39+
}
40+
41+
if (filePath.length === 0) {
42+
throw new Error(`${FILE_PATH_ERROR}, but got '' (empty string).`);
43+
}
44+
45+
if (typeof tarPath !== 'string') {
46+
throw new TypeError(`${TAR_PATH_ERROR}, but got a non-string value ${inspectWithKind(tarPath)}.`);
47+
}
48+
49+
if (tarPath.length === 0) {
50+
throw new Error(`${TAR_PATH_ERROR}, but got '' (empty string).`);
51+
}
52+
53+
const absoluteFilePath = resolve(filePath);
54+
const absoluteTarPath = resolve(tarPath);
55+
const dirPath = dirname(absoluteFilePath);
56+
57+
if (absoluteFilePath === absoluteTarPath) {
58+
throw new Error(`Source file path must be different from the archive path. Both were specified to ${
59+
absoluteFilePath
60+
}.`);
61+
}
62+
63+
if (options !== undefined) {
64+
if (!isPlainObj(options)) {
65+
throw new TypeError(`Expected a plain object to set file-to-tar options, but got ${
66+
inspectWithKind(options)
67+
}.`);
68+
}
69+
} else {
70+
options = {};
71+
}
72+
73+
for (const optionName of unsupportedOptions) {
74+
const val = options[optionName];
75+
76+
if (val !== undefined) {
77+
throw new Error(`file-to-tar doesn't support \`${optionName}\` option, but ${
78+
inspectWithKind(val)
79+
} was provided.`);
80+
}
81+
}
82+
83+
if (options.tarTransform !== undefined) {
84+
if (!isStream(options.tarTransform)) {
85+
throw new TypeError(`${TAR_TRANSFORM_ERROR}, but got a non-stream value ${
86+
inspectWithKind(options.tarTransform)
87+
}.`);
88+
}
89+
90+
if (!isStream.transform(options.tarTransform)) {
91+
throw new TypeError(`${TAR_TRANSFORM_ERROR}, but got a ${
92+
['duplex', 'writable', 'readable'].find(type => isStream[type](options.tarTransform))
93+
} stream instead.`);
94+
}
95+
}
96+
97+
let cancel;
98+
99+
lstat(absoluteFilePath, (lstatErr, stat) => {
100+
if (lstatErr) {
101+
observer.error(lstatErr);
102+
return;
103+
}
104+
105+
if (!stat.isFile()) {
106+
observer.error(new Error(`Expected ${absoluteFilePath} to be a file path, but it was a ${
107+
stat.isDirectory() ? 'directory' : 'symbolic link'
108+
}.`));
109+
110+
return;
111+
}
112+
113+
let firstWriteFailed = false;
114+
115+
const firstWriteStream = fs.createWriteStream(tarPath, options).on('error', err => {
116+
if (err.code === 'EISDIR') {
117+
err.message = `Tried to write an archive file to ${absoluteTarPath}, but a directory already exists there.`;
118+
observer.error(err);
119+
120+
return;
121+
}
122+
123+
firstWriteFailed = true;
124+
});
125+
126+
mkdirp(dirname(tarPath), Object.assign({fs}, options), mkdirpErr => {
127+
if (mkdirpErr) {
128+
observer.error(mkdirpErr);
129+
return;
130+
}
131+
132+
const packStream = pack(dirPath, Object.assign({fs}, options, {
133+
entries: [basename(filePath)],
134+
map(header) {
135+
if (options.map) {
136+
header = options.map(header);
137+
}
138+
139+
return header;
140+
},
141+
mapStream(fileStream, header) {
142+
const newStream = options.mapStream ? options.mapStream(fileStream, header) : fileStream;
143+
144+
if (!isStream.readable(newStream)) {
145+
packStream.emit('error', new TypeError(`${MAP_STREAM_ERROR}${
146+
isStream(newStream) ?
147+
' that is readable, but returned a non-readable stream' :
148+
`, but returned a non-stream value ${inspectWithKind(newStream)}`
149+
}.`));
150+
151+
return new PassThrough();
152+
}
153+
154+
let bytes = 0;
155+
156+
observer.next({bytes, header});
157+
158+
return newStream.pipe(new Transform({
159+
transform(chunk, encoding, cb) {
160+
bytes += chunk.length;
161+
162+
observer.next({bytes, header});
163+
cb(null, chunk);
164+
}
165+
}));
166+
}
167+
}));
168+
169+
function getDest() {
170+
return firstWriteFailed ? fs.createWriteStream(tarPath, options) : firstWriteStream;
171+
}
172+
173+
cancel = cancelablePump(options.tarTransform ? [
174+
packStream,
175+
options.tarTransform,
176+
getDest()
177+
] : [
178+
packStream,
179+
getDest()
180+
], err => {
181+
if (err) {
182+
observer.error(err);
183+
return;
184+
}
185+
186+
observer.complete();
187+
});
188+
});
189+
});
190+
191+
return function cancelCompression() {
192+
if (cancel) {
193+
cancel();
194+
}
195+
};
196+
});
198197
};

‎package-lock.json

+4,466-3,239
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+45-47
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
11
{
2-
"name": "file-to-tar",
3-
"version": "0.2.2",
4-
"description": "Create a tar archive from a single file",
5-
"repository": "shinnn/file-to-tar",
6-
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
7-
"scripts": {
8-
"pretest": "eslint --fix --format=codeframe index.js test.js",
9-
"test": "nyc --reporter=html --reporter=text node test.js"
10-
},
11-
"license": "ISC",
12-
"files": [
13-
"index.js"
14-
],
15-
"keywords": [
16-
"file",
17-
"tar",
18-
"archive",
19-
"compress",
20-
"compression",
21-
"pack",
22-
"progress",
23-
"observable"
24-
],
25-
"dependencies": {
26-
"cancelable-pump": "^0.2.0",
27-
"graceful-fs": "^4.1.11",
28-
"inspect-with-kind": "^1.0.3",
29-
"is-plain-obj": "^1.1.0",
30-
"is-stream": "^1.1.0",
31-
"mkdirp": "^0.5.1",
32-
"tar-fs": "^1.16.0",
33-
"zen-observable": "^0.6.0"
34-
},
35-
"devDependencies": {
36-
"@shinnn/eslint-config-node": "^4.0.2",
37-
"create-symlink": "^1.0.0",
38-
"enumerate-files": "^1.0.0",
39-
"eslint": "^4.12.0",
40-
"make-dir": "^1.1.0",
41-
"nyc": "^11.3.0",
42-
"rmfr": "^1.0.3",
43-
"tape": "^4.8.0",
44-
"tar": "^4.0.2"
45-
},
46-
"eslintConfig": {
47-
"extends": "@shinnn/node"
48-
}
2+
"name": "file-to-tar",
3+
"version": "0.2.2",
4+
"description": "Create a tar archive from a single file",
5+
"repository": "shinnn/file-to-tar",
6+
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
7+
"scripts": {
8+
"pretest": "eslint --fix --format=codeframe index.js test.js",
9+
"test": "nyc --reporter=html --reporter=text node test.js"
10+
},
11+
"license": "ISC",
12+
"files": [
13+
"index.js"
14+
],
15+
"keywords": [
16+
"file",
17+
"tar",
18+
"archive",
19+
"compress",
20+
"compression",
21+
"pack",
22+
"progress",
23+
"observable"
24+
],
25+
"dependencies": {
26+
"cancelable-pump": "^0.2.0",
27+
"graceful-fs": "^4.1.11",
28+
"inspect-with-kind": "^1.0.4",
29+
"is-plain-obj": "^1.1.0",
30+
"is-stream": "^1.1.0",
31+
"mkdirp": "^0.5.1",
32+
"tar-fs": "^1.16.0",
33+
"zen-observable": "^0.6.1"
34+
},
35+
"devDependencies": {
36+
"@shinnn/eslint-config-node": "^5.0.0",
37+
"enumerate-files": "^2.0.0",
38+
"eslint": "^4.19.0",
39+
"nyc": "^11.6.0",
40+
"rmfr": "^2.0.0",
41+
"tape": "^4.9.0",
42+
"tar": "^4.4.1"
43+
},
44+
"eslintConfig": {
45+
"extends": "@shinnn/node"
46+
}
4947
}

‎test.js

+257-256
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.