@actions/artifact
Version:
Actions artifact lib
52 lines • 2.43 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import * as stream from 'stream';
import * as fs from 'fs';
import { realpath } from 'fs/promises';
import * as core from '@actions/core';
import { getUploadChunkSize } from '../shared/config.js';
// Custom stream transformer so we can set the highWaterMark property
// See https://github.com/nodejs/node/issues/8855
export class WaterMarkedUploadStream extends stream.Transform {
constructor(bufferSize) {
super({
highWaterMark: bufferSize
});
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_transform(chunk, enc, cb) {
cb(null, chunk);
}
}
export function createRawFileUploadStream(filePath) {
return __awaiter(this, void 0, void 0, function* () {
core.debug(`Creating raw file upload stream for: ${filePath}`);
const bufferSize = getUploadChunkSize();
const uploadStream = new WaterMarkedUploadStream(bufferSize);
// Check if symlink and resolve the source path
let sourcePath = filePath;
const stats = yield fs.promises.lstat(filePath);
if (stats.isSymbolicLink()) {
sourcePath = yield realpath(filePath);
}
// Create a read stream from the file and pipe it to the upload stream
const fileStream = fs.createReadStream(sourcePath, {
highWaterMark: bufferSize
});
fileStream.on('error', error => {
core.error('An error has occurred while reading the file for upload');
core.error(String(error));
uploadStream.destroy(new Error('An error has occurred during file read for the artifact'));
});
fileStream.pipe(uploadStream);
return uploadStream;
});
}
//# sourceMappingURL=stream.js.map