From 131e247bd27da8e55f6650759639e4a52b3e7674 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Tue, 17 Dec 2019 14:22:32 -0500 Subject: [PATCH] Change to on end --- dist/restore/index.js | 8 ++++++-- dist/save/index.js | 8 ++++++-- src/cacheHttpClient.ts | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index 983c7a3..efe2e13 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -1624,8 +1624,8 @@ function saveCache(cacheId, archivePath) { // Upload Chunks const stream = fs.createReadStream(archivePath); let streamIsClosed = false; - stream.on("close", () => { - core.debug("Stream is closed"); + stream.on("end", () => { + core.debug("Stream is ended"); streamIsClosed = true; }); const resourceUrl = getCacheApiUrl() + cacheId.toString(); @@ -1634,6 +1634,10 @@ function saveCache(cacheId, archivePath) { while (!streamIsClosed) { core.debug(`Offset: ${offset}`); const chunk = stream.read(MAX_CHUNK_SIZE); + if (chunk == null) { + core.debug(`Chunk is null, reading is over?`); + break; + } uploads.push(uploadChunk(restClient, resourceUrl, chunk, offset)); offset += MAX_CHUNK_SIZE; } diff --git a/dist/save/index.js b/dist/save/index.js index 6e08235..320fc1e 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -1624,8 +1624,8 @@ function saveCache(cacheId, archivePath) { // Upload Chunks const stream = fs.createReadStream(archivePath); let streamIsClosed = false; - stream.on("close", () => { - core.debug("Stream is closed"); + stream.on("end", () => { + core.debug("Stream is ended"); streamIsClosed = true; }); const resourceUrl = getCacheApiUrl() + cacheId.toString(); @@ -1634,6 +1634,10 @@ function saveCache(cacheId, archivePath) { while (!streamIsClosed) { core.debug(`Offset: ${offset}`); const chunk = stream.read(MAX_CHUNK_SIZE); + if (chunk == null) { + core.debug(`Chunk is null, reading is over?`); + break; + } uploads.push(uploadChunk(restClient, resourceUrl, chunk, offset)); offset += MAX_CHUNK_SIZE; } diff --git a/src/cacheHttpClient.ts b/src/cacheHttpClient.ts index dbd4a59..b8aade7 100644 --- a/src/cacheHttpClient.ts +++ b/src/cacheHttpClient.ts @@ -185,8 +185,8 @@ export async function saveCache( // Upload Chunks const stream = fs.createReadStream(archivePath); let streamIsClosed = false; - stream.on("close", () => { - core.debug("Stream is closed"); + stream.on("end", () => { + core.debug("Stream is ended"); streamIsClosed = true; }); @@ -196,6 +196,10 @@ export async function saveCache( while (!streamIsClosed) { core.debug(`Offset: ${offset}`); const chunk: Buffer = stream.read(MAX_CHUNK_SIZE); + if (chunk == null) { + core.debug(`Chunk is null, reading is over?`); + break; + } uploads.push(uploadChunk(restClient, resourceUrl, chunk, offset)); offset += MAX_CHUNK_SIZE; }