googleapis-common
Advanced tools
Comparing version 4.1.0 to 4.1.1-beta.0
@@ -168,7 +168,59 @@ "use strict"; | ||
} | ||
function multipartUpload(multipart) { | ||
const boundary = uuid.v4(); | ||
const finale = `--${boundary}--`; | ||
const rStream = new stream.PassThrough({ | ||
flush(callback) { | ||
this.push('\r\n'); | ||
this.push(finale); | ||
callback(); | ||
}, | ||
}); | ||
const pStream = new ProgressStream(); | ||
const isStream = isReadableStream(multipart[1].body); | ||
headers['Content-Type'] = `multipart/related; boundary=${boundary}`; | ||
for (const part of multipart) { | ||
const preamble = `--${boundary}\r\nContent-Type: ${part['Content-Type']}\r\n\r\n`; | ||
rStream.push(preamble); | ||
if (typeof part.body === 'string') { | ||
rStream.push(part.body); | ||
rStream.push('\r\n'); | ||
} | ||
else { | ||
// Gaxios does not natively support onUploadProgress in node.js. | ||
// Pipe through the pStream first to read the number of bytes read | ||
// for the purpose of tracking progress. | ||
pStream.on('progress', bytesRead => { | ||
if (options.onUploadProgress) { | ||
options.onUploadProgress({ bytesRead }); | ||
} | ||
}); | ||
part.body.pipe(pStream).pipe(rStream); | ||
} | ||
} | ||
if (!isStream) { | ||
rStream.push(finale); | ||
rStream.push(null); | ||
} | ||
options.data = rStream; | ||
} | ||
function browserMultipartUpload(multipart) { | ||
const boundary = uuid.v4(); | ||
const finale = `--${boundary}--`; | ||
headers['Content-Type'] = `multipart/related; boundary=${boundary}`; | ||
let content = ''; | ||
for (const part of multipart) { | ||
const preamble = `--${boundary}\r\nContent-Type: ${part['Content-Type']}\r\n\r\n`; | ||
content += preamble; | ||
if (typeof part.body === 'string') { | ||
content += part.body; | ||
content += '\r\n'; | ||
} | ||
} | ||
content += finale; | ||
options.data = content; | ||
} | ||
if (parameters.mediaUrl && media.body) { | ||
options.url = parameters.mediaUrl; | ||
if (resource) { | ||
// gaxios doesn't support multipart/related uploads, so it has to | ||
// be implemented here. | ||
params.uploadType = 'multipart'; | ||
@@ -182,38 +234,10 @@ const multipart = [ | ||
]; | ||
const boundary = uuid.v4(); | ||
const finale = `--${boundary}--`; | ||
const rStream = new stream.PassThrough({ | ||
flush(callback) { | ||
this.push('\r\n'); | ||
this.push(finale); | ||
callback(); | ||
}, | ||
}); | ||
const pStream = new ProgressStream(); | ||
const isStream = isReadableStream(multipart[1].body); | ||
headers['Content-Type'] = `multipart/related; boundary=${boundary}`; | ||
for (const part of multipart) { | ||
const preamble = `--${boundary}\r\nContent-Type: ${part['Content-Type']}\r\n\r\n`; | ||
rStream.push(preamble); | ||
if (typeof part.body === 'string') { | ||
rStream.push(part.body); | ||
rStream.push('\r\n'); | ||
} | ||
else { | ||
// Gaxios does not natively support onUploadProgress in node.js. | ||
// Pipe through the pStream first to read the number of bytes read | ||
// for the purpose of tracking progress. | ||
pStream.on('progress', bytesRead => { | ||
if (options.onUploadProgress) { | ||
options.onUploadProgress({ bytesRead }); | ||
} | ||
}); | ||
part.body.pipe(pStream).pipe(rStream); | ||
} | ||
if (!isbrowser_1.isBrowser()) { | ||
// gaxios doesn't support multipart/related uploads, so it has to | ||
// be implemented here. | ||
multipartUpload(multipart); | ||
} | ||
if (!isStream) { | ||
rStream.push(finale); | ||
rStream.push(null); | ||
else { | ||
browserMultipartUpload(multipart); | ||
} | ||
options.data = rStream; | ||
} | ||
@@ -220,0 +244,0 @@ else { |
{ | ||
"name": "googleapis-common", | ||
"version": "4.1.0", | ||
"version": "4.1.1-beta.0", | ||
"description": "A common tooling library used by the googleapis npm module. You probably don't want to use this directly.", | ||
@@ -27,3 +27,5 @@ "repository": "googleapis/nodejs-googleapis-common", | ||
"predocs-test": "npm run docs", | ||
"prelint": "cd samples; npm link ../; npm i" | ||
"prelint": "cd samples; npm link ../; npm install", | ||
"clean": "gts clean", | ||
"precompile": "gts clean" | ||
}, | ||
@@ -62,3 +64,3 @@ "keywords": [], | ||
"karma-firefox-launcher": "^1.1.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-mocha": "^2.0.0", | ||
"karma-remap-coverage": "^0.1.5", | ||
@@ -72,6 +74,6 @@ "karma-sourcemap-loader": "^0.3.7", | ||
"nock": "^12.0.0", | ||
"null-loader": "^3.0.0", | ||
"puppeteer": "^2.0.0", | ||
"tmp": "^0.1.0", | ||
"ts-loader": "^6.0.4", | ||
"null-loader": "^4.0.0", | ||
"puppeteer": "^3.0.0", | ||
"tmp": "^0.2.0", | ||
"ts-loader": "^7.0.0", | ||
"typescript": "^3.8.3", | ||
@@ -78,0 +80,0 @@ "webpack": "^4.35.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71161
1056
2