Skip to content

Commit df050ac

Browse files
committedFeb 24, 2020
Require Node.js 10
1 parent 4668c5a commit df050ac

File tree

6 files changed

+30
-32
lines changed

6 files changed

+30
-32
lines changed
 

‎.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ language: node_js
66
node_js:
77
- '12'
88
- '10'
9-
- '8'
109
after_success:
1110
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'

‎index.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@ const cpFileAsync = async (source, destination, options, progressEmitter) => {
1111
const stat = await fs.stat(source);
1212
progressEmitter.size = stat.size;
1313

14-
const read = await fs.createReadStream(source);
14+
const readStream = await fs.createReadStream(source);
1515
await fs.makeDir(path.dirname(destination));
16-
const write = fs.createWriteStream(destination, {flags: options.overwrite ? 'w' : 'wx'});
17-
read.on('data', () => {
18-
progressEmitter.written = write.bytesWritten;
16+
const writeStream = fs.createWriteStream(destination, {flags: options.overwrite ? 'w' : 'wx'});
17+
18+
readStream.on('data', () => {
19+
progressEmitter.written = writeStream.bytesWritten;
1920
});
20-
read.once('error', error => {
21+
22+
readStream.once('error', error => {
2123
readError = new CpFileError(`Cannot read from \`${source}\`: ${error.message}`, error);
22-
write.end();
24+
writeStream.end();
2325
});
2426

25-
let updateStats = false;
27+
let shouldUpdateStats = false;
2628
try {
27-
const writePromise = pEvent(write, 'close');
28-
read.pipe(write);
29+
const writePromise = pEvent(writeStream, 'close');
30+
readStream.pipe(writeStream);
2931
await writePromise;
3032
progressEmitter.written = progressEmitter.size;
31-
updateStats = true;
33+
shouldUpdateStats = true;
3234
} catch (error) {
3335
throw new CpFileError(`Cannot write to \`${destination}\`: ${error.message}`, error);
3436
}
@@ -37,7 +39,7 @@ const cpFileAsync = async (source, destination, options, progressEmitter) => {
3739
throw readError;
3840
}
3941

40-
if (updateStats) {
42+
if (shouldUpdateStats) {
4143
const stats = await fs.lstat(source);
4244

4345
return Promise.all([
@@ -60,8 +62,8 @@ const cpFile = (source, destination, options) => {
6062

6163
const progressEmitter = new ProgressEmitter(path.resolve(source), path.resolve(destination));
6264
const promise = cpFileAsync(source, destination, options, progressEmitter);
63-
promise.on = (...args) => {
64-
progressEmitter.on(...args);
65+
promise.on = (...arguments_) => {
66+
progressEmitter.on(...arguments_);
6567
return promise;
6668
};
6769

‎license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

‎package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"description": "Copy a file",
55
"license": "MIT",
66
"repository": "sindresorhus/cp-file",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
1213
"engines": {
13-
"node": ">=8"
14+
"node": ">=10"
1415
},
1516
"scripts": {
1617
"test": "xo && nyc ava && tsd"
@@ -47,12 +48,12 @@
4748
"ava": "^2.1.0",
4849
"clear-module": "^3.1.0",
4950
"coveralls": "^3.0.4",
50-
"del": "^4.1.1",
51+
"del": "^5.1.0",
5152
"import-fresh": "^3.0.0",
52-
"nyc": "^14.1.1",
53-
"sinon": "^7.3.1",
54-
"tsd": "^0.7.3",
53+
"nyc": "^15.0.0",
54+
"sinon": "^9.0.0",
55+
"tsd": "^0.11.0",
5556
"uuid": "^3.3.2",
56-
"xo": "^0.24.0"
57+
"xo": "^0.26.1"
5758
}
5859
}

‎progress-emitter.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ class ProgressEmitter extends EventEmitter {
1010
this._destination = destination;
1111
}
1212

13+
get written() {
14+
return written.get(this);
15+
}
16+
1317
set written(value) {
1418
written.set(this, value);
1519
this.emitProgress();
1620
}
1721

18-
get written() {
19-
return written.get(this);
20-
}
21-
2222
emitProgress() {
2323
const {size, written} = this;
24+
2425
this.emit('progress', {
2526
src: this._source,
2627
dest: this._destination,

‎readme.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
> Copy a file
44
5-
65
## Highlights
76

87
- Fast by using streams in the async version and [`fs.copyFileSync()`](https://nodejs.org/api/fs.html#fs_fs_copyfilesync_src_dest_flags) in the synchronous version.
@@ -11,14 +10,12 @@
1110
- Can be safe by turning off [overwriting](#optionsoverwrite).
1211
- User-friendly errors.
1312

14-
1513
## Install
1614

1715
```
1816
$ npm install cp-file
1917
```
2018

21-
2219
## Usage
2320

2421
```js
@@ -30,7 +27,6 @@ const cpFile = require('cp-file');
3027
})();
3128
```
3229

33-
3430
## API
3531

3632
### cpFile(source, destination, options?)
@@ -57,7 +53,7 @@ Type: `object`
5753

5854
##### overwrite
5955

60-
Type: `boolean`<br>
56+
Type: `boolean`\
6157
Default: `true`
6258

6359
Overwrite existing destination file.
@@ -102,7 +98,6 @@ const cpFile = require('cp-file');
10298
})();
10399
```
104100

105-
106101
## Related
107102

108103
- [cpy](https://github.com/sindresorhus/cpy) - Copy files

0 commit comments

Comments
 (0)
Please sign in to comment.