Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete solution to node v10 compatibility #24

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,7 @@ const fsP = pify(fs);

exports.closeSync = fs.closeSync.bind(fs);
exports.createWriteStream = fs.createWriteStream.bind(fs);

exports.createReadStream = (path, options) => new Promise((resolve, reject) => {
const read = fs.createReadStream(path, options);

read.on('error', err => {
reject(new CpFileError(`Cannot read from \`${path}\`: ${err.message}`, err));
});

read.on('readable', () => {
resolve(read);
});

read.on('end', () => {
resolve(read);
});
});
exports.createReadStream = fs.createReadStream.bind(fs);

exports.stat = path => fsP.stat(path).catch(err => {
throw new CpFileError(`Cannot stat path \`${path}\`: ${err.message}`, err);
Expand Down
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ module.exports = (src, dest, opts) => {
.then(stat => {
progressEmitter.size = stat.size;
})
.then(() => fs.createReadStream(src))
.then(read => fs.makeDir(path.dirname(dest)).then(() => read))
.then(read => new Promise((resolve, reject) => {
.then(() => fs.makeDir(path.dirname(dest)))
.then(() => new Promise((resolve, reject) => {
const read = fs.createReadStream(src);
const write = fs.createWriteStream(dest, {flags: opts.overwrite ? 'w' : 'wx'});

read.on('error', err => {
reject(new CpFileError(`Cannot read from \`${path}\`: ${err.message}`, err));
});

read.on('data', () => {
progressEmitter.written = write.bytesWritten;
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"make-dir": "^1.0.0",
"nested-error-stacks": "^2.0.0",
"pify": "^3.0.0",
"safe-buffer": "^5.0.1"
"safe-buffer": "^5.1.2"
},
"devDependencies": {
"ava": "*",
Expand Down