-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy path_util.js
More file actions
41 lines (32 loc) · 935 Bytes
/
_util.js
File metadata and controls
41 lines (32 loc) · 935 Bytes
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
var fs = require('fs')
var path = require('path')
var stream = require('stream')
exports.filePath = function filePath (name) {
return path.join(__dirname, 'files', name)
}
exports.file = function file (name) {
return fs.createReadStream(this.filePath(name))
}
exports.fileSize = function fileSize (path) {
return fs.statSync(path).size
}
exports.fileSizeByName = function fileSizeByName (name) {
return this.fileSize(this.filePath(name))
}
exports.readDir = function readDir (dirPath) {
return fs.readdirSync(dirPath)
}
exports.submitForm = function submitForm (multer, form, cb) {
form.getLength(function (err, length) {
if (err) return cb(err)
var req = new stream.PassThrough()
form.pipe(req)
req.headers = {
'content-type': 'multipart/form-data; boundary=' + form.getBoundary(),
'content-length': length
}
multer(req, null, function (err) {
cb(err, req)
})
})
}