feat(Xapi#putResource): accept buffers
This commit is contained in:
parent
69c48e2770
commit
8fe3b1a368
@ -37,14 +37,14 @@
|
||||
"debug": "^2.6.8",
|
||||
"event-to-promise": "^0.8.0",
|
||||
"exec-promise": "^0.7.0",
|
||||
"http-request-plus": "^0.1.4",
|
||||
"http-request-plus": "^0.1.5",
|
||||
"json-rpc-protocol": "^0.11.2",
|
||||
"kindof": "^2.0.0",
|
||||
"lodash": "^4.17.4",
|
||||
"make-error": "^1.3.0",
|
||||
"minimist": "^1.2.0",
|
||||
"ms": "^2.0.0",
|
||||
"promise-toolbox": "^0.8.2",
|
||||
"promise-toolbox": "^0.9.1",
|
||||
"pw": "0.0.4",
|
||||
"xmlrpc": "^1.3.2",
|
||||
"xo-collection": "^0.4.1"
|
||||
|
@ -8,7 +8,6 @@ import { EventEmitter } from 'events'
|
||||
import { filter, forEach, isArray, isObject, map, noop, reduce, startsWith } from 'lodash'
|
||||
import {
|
||||
cancelable,
|
||||
CancelToken,
|
||||
catchPlus as pCatch,
|
||||
delay as pDelay
|
||||
} from 'promise-toolbox'
|
||||
@ -332,25 +331,24 @@ export class Xapi extends EventEmitter {
|
||||
}
|
||||
|
||||
@cancelable
|
||||
putResource ($cancelToken, stream, pathname, {
|
||||
putResource ($cancelToken, body, pathname, {
|
||||
host,
|
||||
query
|
||||
} = {}) {
|
||||
const headers = {}
|
||||
|
||||
// Xen API does not support chunk encoding.
|
||||
const { length } = stream
|
||||
if (length === undefined) {
|
||||
const { length } = body
|
||||
if (length === undefined && typeof body.pipe === 'function') {
|
||||
// add a fake huge content length (1 PiB)
|
||||
headers['content-length'] = '1125899906842624'
|
||||
|
||||
const { cancel, token } = CancelToken.source()
|
||||
$cancelToken = CancelToken.race([ $cancelToken, token ])
|
||||
|
||||
// when the data has been emitted, close the connection
|
||||
stream.on('end', () => {
|
||||
$cancelToken = $cancelToken.fork(cancel => {
|
||||
body.on('end', () => {
|
||||
setTimeout(cancel, 1e3)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return httpRequest.put(
|
||||
@ -360,7 +358,7 @@ export class Xapi extends EventEmitter {
|
||||
hostname: this.getObject(host).address
|
||||
},
|
||||
{
|
||||
body: stream,
|
||||
body,
|
||||
headers,
|
||||
path: pathname,
|
||||
query: {
|
||||
|
@ -1897,13 +1897,13 @@ html-encoding-sniffer@^1.0.1:
|
||||
dependencies:
|
||||
whatwg-encoding "^1.0.1"
|
||||
|
||||
http-request-plus@^0.1.4:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/http-request-plus/-/http-request-plus-0.1.4.tgz#c99cd36366e96c13f92da5954b3a2fd2ce2c531e"
|
||||
http-request-plus@^0.1.5:
|
||||
version "0.1.5"
|
||||
resolved "https://registry.yarnpkg.com/http-request-plus/-/http-request-plus-0.1.5.tgz#9aead8b230586397928ecbb9a6bed96a3bfe2210"
|
||||
dependencies:
|
||||
is-redirect "^1.0.0"
|
||||
lodash "^4.17.4"
|
||||
promise-toolbox "^0.8.2"
|
||||
promise-toolbox "^0.9.1"
|
||||
|
||||
http-signature@~1.1.0:
|
||||
version "1.1.1"
|
||||
@ -2635,7 +2635,7 @@ lru-cache@^4.0.1:
|
||||
pseudomap "^1.0.1"
|
||||
yallist "^2.0.0"
|
||||
|
||||
make-error@^1.0.2, make-error@^1.2.0, make-error@^1.2.2, make-error@^1.3.0:
|
||||
make-error@^1.0.2, make-error@^1.2.0, make-error@^1.2.3, make-error@^1.3.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.0.tgz#52ad3a339ccf10ce62b4040b708fe707244b8b96"
|
||||
|
||||
@ -3010,11 +3010,11 @@ progress@^1.1.8:
|
||||
version "1.1.8"
|
||||
resolved "https://registry.yarnpkg.com/progress/-/progress-1.1.8.tgz#e260c78f6161cdd9b0e56cc3e0a85de17c7a57be"
|
||||
|
||||
promise-toolbox@^0.8.2:
|
||||
version "0.8.2"
|
||||
resolved "https://registry.yarnpkg.com/promise-toolbox/-/promise-toolbox-0.8.2.tgz#91722a364e6a2d6d13319491da3068b7de0b348f"
|
||||
promise-toolbox@^0.9.1:
|
||||
version "0.9.1"
|
||||
resolved "https://registry.yarnpkg.com/promise-toolbox/-/promise-toolbox-0.9.1.tgz#01ad022f7a1272f51049b9561ac522041360fc37"
|
||||
dependencies:
|
||||
make-error "^1.2.2"
|
||||
make-error "^1.2.3"
|
||||
|
||||
prr@~0.0.0:
|
||||
version "0.0.0"
|
||||
|
Loading…
Reference in New Issue
Block a user