3
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-23 03:45:31 +00:00

Use promisify of stream.pipeline for downloading

This commit is contained in:
Dave Hadka 2020-04-29 09:31:53 -04:00 committed by Aiqiao Yan
parent 2a973a0f4e
commit ec7f7ebd08
3 changed files with 33 additions and 28 deletions

View file

@ -1,12 +1,14 @@
import * as core from "@actions/core";
import * as fs from "fs";
import { BearerCredentialHandler } from "@actions/http-client/auth";
import { HttpClient, HttpCodes } from "@actions/http-client";
import { BearerCredentialHandler } from "@actions/http-client/auth";
import {
IHttpClientResponse,
IRequestOptions,
ITypedResponse
} from "@actions/http-client/interfaces";
import * as fs from "fs";
import * as stream from "stream";
import * as util from "util";
import { SocketTimeout } from "./constants";
import {
@ -109,13 +111,10 @@ export async function getCacheEntry(
async function pipeResponseToStream(
response: IHttpClientResponse,
stream: NodeJS.WritableStream
output: NodeJS.WritableStream
): Promise<void> {
return new Promise(resolve => {
response.message.pipe(stream).on("close", () => {
resolve();
});
});
const pipeline = util.promisify(stream.pipeline);
await pipeline(response.message, output);
}
export async function downloadCache(