mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 05:00:15 +00:00
23 lines
586 B
JavaScript
23 lines
586 B
JavaScript
module.exports = upload
|
|
|
|
var fs = require('fs')
|
|
, Stream = require("stream").Stream
|
|
|
|
function upload (where, file, etag, nofollow, cb) {
|
|
if (typeof nofollow === "function") cb = nofollow, nofollow = false
|
|
if (typeof etag === "function") cb = etag, etag = null
|
|
|
|
if (file instanceof Stream) {
|
|
return this.request("PUT", where, file, etag, nofollow, cb)
|
|
}
|
|
|
|
fs.stat(file, function (er, stat) {
|
|
if (er) return cb(er)
|
|
var s = fs.createReadStream(file)
|
|
s.size = stat.size
|
|
s.on("error", cb)
|
|
|
|
this.request("PUT", where, s, etag, nofollow, cb)
|
|
}.bind(this))
|
|
}
|