@@ -4,6 +4,8 @@ import http from 'node:http'
44import { tmpdir } from 'node:os'
55import { dirname , join , relative , resolve , sep } from 'node:path'
66import { platform } from 'node:process'
7+ import stream from 'node:stream'
8+ import { promisify } from 'node:util'
79
810import { ListResponse } from './backend/list.ts'
911import { decodeMetadata , encodeMetadata , METADATA_HEADER_INTERNAL } from './metadata.ts'
@@ -21,6 +23,10 @@ export enum Operation {
2123 SET = 'set' ,
2224}
2325
26+ // TODO: Replace with `promises` import of `node:stream` once we can drop
27+ // support for Node 14.
28+ const pipeline = promisify ( stream . pipeline )
29+
2430interface BlobsServerOptions {
2531 /**
2632 * Whether debug-level information should be logged, such as internal errors
@@ -271,12 +277,7 @@ export class BlobsServer {
271277 const tempDataPath = join ( tempDirectory , relativeDataPath )
272278
273279 await fs . mkdir ( dirname ( tempDataPath ) , { recursive : true } )
274-
275- await new Promise ( ( resolve , reject ) => {
276- req . pipe ( createWriteStream ( tempDataPath ) )
277- req . on ( 'end' , resolve )
278- req . on ( 'error' , reject )
279- } )
280+ await pipeline ( req , createWriteStream ( tempDataPath ) )
280281
281282 await fs . mkdir ( dirname ( dataPath ) , { recursive : true } )
282283 await fs . copyFile ( tempDataPath , dataPath )
0 commit comments