-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
68 lines (51 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Module dependencies
*/
var path = require('path');
var _ = require('@sailshq/lodash');
var fsx = require('fs-extra');
var buildDiskReceiverStream = require('./standalone/build-disk-receiver-stream');
/**
* skipper-disk
*
* @type {Function}
* @param {Object} options
* @return {Object}
*/
module.exports = function SkipperDisk(options) {
options = options || {};
var adapter = {};
adapter.rm = function(fd, cb) {
return fsx.unlink(fd, function(err) {
// Ignore "doesn't exist" errors
if (err && (typeof err !== 'object' || err.code !== 'ENOENT')) {
return cb(err);
}
else {
return cb();
}
});
};
adapter.ls = function(dirpath, cb) {
return fsx.readdir(dirpath, function (err, files){
if (err) { return cb(err); }
files = _.reduce(_.isArray(files)?files:[], function (m, filename){
var fd = path.join(dirpath,filename);
m.push(fd);
return m;
}, []);
cb(undefined, files);
});
};
adapter.read = function(fd, cb) {
if (cb) {
return fsx.readFile(fd, cb);
} else {
return fsx.createReadStream(fd);
}
};
adapter.receive = function(opts) {
return buildDiskReceiverStream(_.defaults(opts, options), adapter);
};
return adapter;
};