Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scp2

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scp2 - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

71

lib/client.js

@@ -153,13 +153,4 @@ var fs = require('fs');

var content = options.content;
if (!Buffer.isBuffer(content)) {
content = new Buffer(content, options.encoding);
}
var chunkSize = options.chunkSize || 32768;
var length = parseInt((content.length - 1) / 204800, 10) + 1;
var contents = [];
for (var i = 0 ; i < length; i++) {
contents.push(content.slice(i * 204800, (i + 1) * 204800));
}
var self = this;

@@ -172,12 +163,44 @@

var lastIndex = 0;
async.eachSeries(contents, function(content, callback) {
sftp.write(handle, content, 0, content.length, lastIndex, function(err) {
lastIndex += content.length;
callback(err);
var lastCursor = 0;
if (Buffer.isBuffer(content)) {
var contents = [];
var length = parseInt((content.length - 1) / chunkSize, 10) + 1;
for (var i = 0 ; i < length; i++) {
contents.push(content.slice(i * chunkSize, (i + 1) * chunkSize));
}
async.eachSeries(contents, function(buf, callback) {
self.emit('transfer', buf, lastCursor, length);
sftp.write(handle, buf, 0, buf.length, lastIndex, function(err) {
lastIndex += buf.length;
lastCursor += 1;
callback(err);
});
}, function(err) {
sftp.close(handle, callback);
});
}, function(err) {
sftp.close(handle, function(err) {
callback(err);
} else if (typeof content === 'number') {
// content is a file descriptor
var length = parseInt((attrs.size - 1) / chunkSize, 10) + 1;
var range = new Array(length);
async.eachSeries(range, function(pos, callback) {
chunkSize = Math.min(chunkSize, attrs.size - lastIndex);
var buf = new Buffer(chunkSize);
fs.read(content, buf, 0, chunkSize, lastIndex, function(err, byteRead, buf) {
self.emit('transfer', buf, lastCursor, length);
sftp.write(handle, buf, 0, buf.length, lastIndex, function(err) {
lastIndex += buf.length;
lastCursor += 1;
callback(err);
});
});
}, function(err) {
sftp.close(handle, function(err) {
fs.close(content, callback);
});
});
});
} else {
throw new Error('Content should be buffer or file descriptor');
}
};

@@ -208,3 +231,3 @@

var self = this, _attrs, _buffer;
var self = this, _attrs, _fd;

@@ -216,7 +239,7 @@ async.waterfall([

function(stats, callback) {
_attrs = util.inspect(stats);
fs.readFile(src, callback);
_attrs = stats;
fs.open(src, 'r', callback);
},
function(buffer, callback) {
_buffer = buffer;
function(fd, callback) {
_fd = fd;
if (/\/$/.test(dest)) {

@@ -232,3 +255,3 @@ self.mkdir(dest, _attrs, callback);

destination: dest,
content: _buffer,
content: _fd,
attrs: _attrs

@@ -235,0 +258,0 @@ }, callback)

{
"name": "scp2",
"version": "0.1.1",
"version": "0.1.2",
"description": "A pure javascript scp program based on ssh2.",

@@ -5,0 +5,0 @@ "author": "Hsiaoming Yang <lepture@me.com>",

@@ -188,5 +188,11 @@ # scp2

- read (src)
- transfer (buffer, uploaded, total)
## Changelog
**2013-06-04** `0.1.2` ~stable
1. Fixed for uploading a large file (beyond the limitation of fs.readFile)
2. Event emit for `transfer`
**2013-06-03** `0.1.1` ~stable

@@ -193,0 +199,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc