Skip to content

Commit

Permalink
SFTPStream: add fileSize option for fast* methods
Browse files Browse the repository at this point in the history
Supplying a valid file size will skip fstat/stat calls.
  • Loading branch information
scout119 authored and mscdex committed Jun 30, 2019
1 parent 894c3eb commit 9941932
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/sftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ function fastXfer(src, dst, srcPath, dstPath, opts, cb) {
//var preserve = false;
var onstep;
var mode;
var fileSize;

if (typeof opts === 'function') {
cb = opts;
Expand All @@ -1007,6 +1008,10 @@ function fastXfer(src, dst, srcPath, dstPath, opts, cb) {
&& opts.chunkSize > 0
&& !isNaN(opts.chunkSize))
chunkSize = opts.chunkSize;
if (typeof opts.fileSize === 'number'
&& opts.fileSize > 0
&& !isNaN(opts.fileSize))
fileSize = opts.fileSize;
if (typeof opts.step === 'function')
onstep = opts.step;
//preserve = (opts.preserve ? true : false);
Expand Down Expand Up @@ -1056,7 +1061,12 @@ function fastXfer(src, dst, srcPath, dstPath, opts, cb) {

srcHandle = sourceHandle;

src.fstat(srcHandle, function tryStat(err, attrs) {
if (fileSize !== undefined)

This comment has been minimized.

Copy link
@unknownbrackets

unknownbrackets Jul 1, 2019

Is it me, or is this backwards?

fileSize NOT undefined -> call fstat on handle
fileSize set to undefined -> pass undefined as size to tryStat with no error.

-[Unknown]

This comment has been minimized.

Copy link
@mscdex

mscdex Jul 1, 2019

Owner

Yep, fixed in 053983a.

src.fstat(srcHandle, tryStat);
else
tryStat(null, { size: fileSize });

function tryStat(err, attrs) {
if (err) {
if (src !== fs) {
// Try stat() for sftp servers that may not support fstat() for
Expand Down Expand Up @@ -1192,7 +1202,7 @@ function fastXfer(src, dst, srcPath, dstPath, opts, cb) {
}
}
});
});
}
});
}
SFTPStream.prototype.fastGet = function(remotePath, localPath, opts, cb) {
Expand Down

0 comments on commit 9941932

Please sign in to comment.