file2stream v1.0.0
file2stream
file2stream is a small package that will return readable stream's from different file sources. For now only supports four types of sources: local, ftp, s3 and http.
Install
npm install file2stream --save
Usage
file2stream expects a options object as first parameter and a string representing the filename as second parameter, depending on which kind of data source you use the data of the options object will vary. file2stream will return a promise that resolves in a stream.
var file2stream = require("file2stream");
var localFilePromise = file2stream.get({type: 'local'}, './public/test.csv');
localFilePromise.then(function(res){
//a readable stream
res.pipe(something);
});
Local source
Get the file from local file system.
var options = { type: 'local' }
FTP source
Get the file from a FTP server. We use JSFtp(https://github.com/sergi/jsftp) as ftp client.
var options = { type: 'ftp', host: "localhost.com", port: 99, // defaults to 21 user: "user", // defaults to "anonymous" pass: "1234" // defaults to "@anonymous" }
HTTP source
Get the file from an http url. Instead of a file name as second parameter file2stream expects an url.
var options = {
type : 'http'
}
S3 source
Get the file from an s3 bucket.
var options = { type : 's3', bucket: 'myBucket', key: 'myS3Key', secret: 'myS3Secret' }
Test
npm run test
if you want to test the s3 source you have to pass the s3 data as env variables. S3_KEY=xxxxxxxx S3_SECRET=xxxxxxxxxx S3_BUCKET=xxxx S3_FILE=xxxxx
8 years ago