-
-
Notifications
You must be signed in to change notification settings - Fork 805
feat: add fs/copy-file
#2201
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
base: develop
Are you sure you want to change the base?
feat: add fs/copy-file
#2201
Conversation
Hi @Planeshifter could you rerun the CI checks so that I can rectify anything that isn't correct? |
@kgryte , @Planeshifter could you rerun the CI check |
/stdlib update-copyright-years |
|
||
mode = 0; | ||
if ( args.length < 2 && ( !flags.source || !flags.destination ) ) { | ||
return cli.error( new Error( 'Both source and destination files must be provided' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message should be updated based on common CLI error conventions.
if ( args.length < 2 && ( !flags.source || !flags.destination ) ) { | ||
return cli.error( new Error( 'Both source and destination files must be provided' ) ); | ||
} | ||
if ( flags.source ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argument handling is somewhat convoluted. Either --source
and --destination
flags are provided OR positional arguments. Further, at L80, we resolve relative to the cwd, but not if flags are provided. We should be consistent.
} | ||
|
||
// Perform copying... | ||
copyFile( src, dest, mode, onCopy ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using async copy in the CLI is not necessary. Using sync is fine and can be faster in common CLI usage contexts.
@@ -0,0 +1,55 @@ | |||
|
|||
{{alias}}( src, dest[, mode], clbk ) | |||
Asynchronously copies src to dest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description should be updated to avoid abbreviations.
Modifiers for copy operation. Default: 0. | ||
|
||
clbk: Function | ||
Callback to invoke upon copying src file to dest file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment.
... if ( err ) { | ||
... console.error( err.message ); | ||
... } | ||
... console.log('src.txt has been copied to dest.txt'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces.
|
||
|
||
{{alias}}.sync( src, dest[, mode] ) | ||
Synchronously copies src to dest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
} | ||
|
||
// Asynchronously copy data from src.txt to dest.txt: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( !isString( dest ) && !isBuffer( dest ) ) { | ||
throw new TypeError( format( 'invalid argument. Second argument must be either a string or a Buffer. Value: `%s`.', dest ) ); | ||
} | ||
if ( !isNumber( mode ) && mode !== null ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above we state that the mode
must be an integer; however, here, we use a weaker check. Furthermore, are only nonnegative integers permitted?
* | ||
* @param {(string|Buffer)} src - source filename to copy | ||
* @param {(string|Buffer)} dest - destination filename of the copy operation | ||
* @param {integer} [mode] - modifiers for copy operation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing default parameter value.
// MAIN // | ||
|
||
/** | ||
* Synchronously copies `src` to `dest`. By default, `dest` is overwritten if it already exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second sentence should be moved to a note.
var fs = require( 'fs' ); | ||
var createReadStream = require( 'fs' ).createReadStream; | ||
var createWriteStream = require( 'fs' ).createWriteStream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three separate imports is not necessary. Use a single import and then refer to the appropriate methods.
* | ||
* @param {(string|Buffer)} src - source filename to copy | ||
* @param {(string|Buffer)} dest - destination filename of the copy operation | ||
* @param {(integer)} [mode] - modifiers for copy operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param {(integer)} [mode] - modifiers for copy operation. | |
* @param {integer} [mode=0] - modifiers for copy operation |
writeStream = createWriteStream( dest ); | ||
readStream.on( 'error', onReadError ); | ||
writeStream.on( 'error', onWriteError ); | ||
writeStream.on( 'finish', onFinish); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writeStream.on( 'finish', onFinish); | |
writeStream.on( 'finish', onFinish ); |
* @private | ||
*/ | ||
function onFinish() { | ||
cb( null ); // Success |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even need to provide an argument here?
adds file system copy file utility to Stdlib
Description
This pull request:
is aligned with the purpose of achievinng feature parity with Node.js fs package. It Brings file system's powerful copy file utility to Stdlib expanding its existing fs utilities. It also tends to make the copy File utility version independent for node. Moreover, with this I also wish to know with what approach do we further add abstractions over the fs utilities.
Questions
No.
Other
Implementation details
-- async version
-- sync version
more --> currently researching on how fs/constants could be implemented for stdlibsuch that further feature parity and version independency are achievable.
Checklist
@stdlib-js/reviewers