forked from max-mapper/gput
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·36 lines (27 loc) · 744 Bytes
/
Copy pathcli.js
File metadata and controls
executable file
·36 lines (27 loc) · 744 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
#!/usr/bin/env node
var path = require('path')
var fs = require('fs')
var mime = require('mime')
var gput = require('./')
var configPath = path.join(process.env.HOME || process.env.USERPROFILE, '.config', 'googleauth.json')
var input
var filename = process.argv[2]
if (!process.stdin.isTTY) {
input = process.stdin
} else if (filename) {
input = fs.createReadStream(filename)
} else {
throw new Error('no input specified')
}
var opts = {
token: JSON.parse(fs.readFileSync(configPath)).access_token
}
if (filename) opts.contentType = mime.lookup(filename)
var put = gput(opts)
input.pipe(put)
put.on('response', function(resp) {
resp.pipe(process.stdout)
})
put.on('error', function(err) {
console.error('Put Error', err)
})