ssh2-sftp-client
Advanced tools
Comparing version 1.0.5 to 1.1.0
{ | ||
"name": "ssh2-sftp-client", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "ssh2 sftp client for node", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -55,6 +55,6 @@ ## SSH2 SFTP Client | ||
#### Get | ||
get a new readable stream for path. | ||
get a new readable stream for path. The encoding is passed to Node Stream (https://nodejs.org/api/stream.html) and it controls how the content is encoded. For example, when downloading binary data, 'null' should be passed (check node stream documentation). Defaults to 'utf8'. | ||
``` | ||
sftp.get(romoteFilePath, [useCompression]); | ||
sftp.get(remoteFilePath, [useCompression], [encoding]); | ||
``` | ||
@@ -66,5 +66,5 @@ | ||
``` | ||
sftp.put(localFilePath, remoteFilePath, [useCompression]); | ||
sftp.put(Buffer, remoteFilePath, [useCompression]); | ||
sftp.put(Stream, remoteFilePath, [useCompression]); | ||
sftp.put(localFilePath, remoteFilePath, [useCompression], [encoding]); | ||
sftp.put(Buffer, remoteFilePath, [useCompression], [encoding]); | ||
sftp.put(Stream, remoteFilePath, [useCompression], [encoding]); | ||
``` | ||
@@ -108,5 +108,9 @@ | ||
### Log | ||
* 2016.05.19: | ||
#### V1.1.0 | ||
- fix: add encoding control support for binary stream | ||
#### V1.0.5: | ||
- fix: multi image upload | ||
- change: remove `this.client.sftp` to `connect` function | ||
@@ -60,6 +60,7 @@ /** | ||
* @param {Object} useCompression, config options | ||
* @param {String} encoding. Encoding for the ReadStream, can be any value supported by node streams. Use 'null' for binary (https://nodejs.org/api/stream.html#stream_readable_setencoding_encoding) | ||
* @return {Promise} stream, readable stream | ||
*/ | ||
SftpClient.prototype.get = function(path, useCompression) { | ||
useCompression = Object.assign({}, {encoding: 'utf8'}, useCompression); | ||
SftpClient.prototype.get = function(path, useCompression, encoding) { | ||
let options = this.getOptions(useCompression, encoding) | ||
@@ -71,3 +72,3 @@ return new Promise((resolve, reject) => { | ||
try { | ||
let stream = sftp.createReadStream(path, useCompression); | ||
let stream = sftp.createReadStream(path, options); | ||
@@ -92,6 +93,7 @@ stream.on('error', reject); | ||
* @param {Object} useCompression [description] | ||
* @param {String} encoding. Encoding for the WriteStream, can be any value supported by node streams. | ||
* @return {[type]} [description] | ||
*/ | ||
SftpClient.prototype.put = function(input, remotePath, useCompression) { | ||
useCompression = Object.assign({}, {encoding: 'utf8'}, useCompression); | ||
SftpClient.prototype.put = function(input, remotePath, useCompression, encoding) { | ||
let options = this.getOptions(useCompression, encoding) | ||
@@ -103,3 +105,3 @@ return new Promise((resolve, reject) => { | ||
if (typeof input === 'string') { | ||
sftp.fastPut(input, remotePath, useCompression, (err) => { | ||
sftp.fastPut(input, remotePath, options, (err) => { | ||
if (err) { | ||
@@ -113,3 +115,3 @@ reject(err); | ||
} | ||
let stream = sftp.createWriteStream(remotePath, useCompression); | ||
let stream = sftp.createWriteStream(remotePath, options); | ||
let data; | ||
@@ -308,2 +310,10 @@ | ||
SftpClient.prototype.getOptions = function(useCompression, encoding){ | ||
if(encoding === undefined){ | ||
encoding = 'utf8'; | ||
} | ||
let options = Object.assign({}, {encoding: encoding}, useCompression); | ||
return options; | ||
}; | ||
module.exports = SftpClient; |
@@ -263,1 +263,24 @@ 'use strict'; | ||
}); | ||
describe('getOptions', () => { | ||
it('encoding should be utf8 if undefined', () => { | ||
return expect(sftp.getOptions()).to.have.property('encoding', 'utf8') | ||
}); | ||
it('encoding should be utf8 if undefined 1', () => { | ||
return expect(sftp.getOptions(false)).to.have.property('encoding', 'utf8') | ||
}); | ||
it('encoding should be utf8 if undefined 2', () => { | ||
return expect(sftp.getOptions(false, undefined)).to.have.property('encoding', 'utf8') | ||
}); | ||
it('encoding should be null if null', () => { | ||
return expect(sftp.getOptions(false, null)).to.have.property('encoding', null) | ||
}); | ||
it('encoding should be hex', () => { | ||
return expect(sftp.getOptions(false, 'hex')).to.have.property('encoding', 'hex') | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23204
578
114