Welcome to mirror list, hosted at ThFree Co, Russian Federation.

upload.js « lib « npm-registry-client « node_modules « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2418997b4411e058e26374d2df26486f4844cb60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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))
}