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

upload.js « lib « npm-registry-client « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f624a266c42389aade4dc36504235168b8fa13bb (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 (uri, 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", uri, { body : file, etag : etag, follow : !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", uri, { body : s, etag : etag, follow : !nofollow }, cb)
  }.bind(this))
}