(options: {
stage: UploadProgressStage;
fileName: string;
startOffset: number;
totalBytes: number;
onProgress?: UploadProgressSink;
})
| 30 | export type UploadProgressSink = (event: UploadProgressEvent) => void; |
| 31 | |
| 32 | export function createUploadProgressTransform(options: { |
| 33 | stage: UploadProgressStage; |
| 34 | fileName: string; |
| 35 | startOffset: number; |
| 36 | totalBytes: number; |
| 37 | onProgress?: UploadProgressSink; |
| 38 | }): Transform { |
| 39 | const { stage, fileName, startOffset, totalBytes, onProgress } = options; |
| 40 | let transferredBytes = startOffset; |
| 41 | const stepBytes = uploadProgressStepBytes(totalBytes); |
| 42 | let nextReportAt = Math.min(totalBytes, startOffset + stepBytes); |
| 43 | return new Transform({ |
| 44 | transform(chunk: Buffer, _encoding, callback) { |
| 45 | transferredBytes = Math.min(totalBytes, transferredBytes + chunk.byteLength); |
| 46 | if (transferredBytes >= nextReportAt) { |
| 47 | onProgress?.({ |
| 48 | type: 'progress', |
| 49 | stage, |
| 50 | fileName, |
| 51 | transferredBytes, |
| 52 | totalBytes, |
| 53 | }); |
| 54 | nextReportAt = Math.min(totalBytes, transferredBytes + stepBytes); |
| 55 | } |
| 56 | callback(null, chunk); |
| 57 | }, |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | export function createStderrUploadProgressReporter(): UploadProgressSink | undefined { |
| 62 | if (process.stderr.isTTY !== true || process.env.CI) return undefined; |
no test coverage detected