Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function ingest (options) {
let resources = [];
const pipeline = stdin().pipe(StreamValues.withParser());
return new Promise((resolve, reject) => {
pipeline.on('data', async ({ value }) => {
if (Array.isArray(value)) {
resources = resources.concat(value);
} else {
resources.push(value);
}
if (resources.length >= options.chunk) {
try {
const payload = resources.slice();
resources = [];
await batchUpload(options, payload);
} catch (err) {
pipeline.destroy(err);
stream.on("response", headers => {
const status: number = headers[HTTP2_HEADER_STATUS] as any
if (status !== HTTP_STATUS_OK) {
reject(new HttpError(status))
return
}
stream.pipe(StreamValues.withParser())
.on("data", (object: any) => {
const data = object.value
if (log.isDebugEnabled) {
log.debug({event: JSON.stringify(data, null, 2)}, "remote builder event")
}
if (data.status != null) {
log.info({status: data.status}, "remote building")
}
else if ("error" in data) {
resolve({files: null, error: data.error})
}
else if ("files" in data) {
this.downloadArtifacts(data.files, data.fileSizes, data.baseUrl)
.then(() => {
stream.destroy()