@@ -4,6 +4,8 @@ import http from 'node:http'
4
4
import { tmpdir } from 'node:os'
5
5
import { dirname , join , relative , resolve , sep } from 'node:path'
6
6
import { platform } from 'node:process'
7
+ import stream from 'node:stream'
8
+ import { promisify } from 'node:util'
7
9
8
10
import { ListResponse } from './backend/list.ts'
9
11
import { decodeMetadata , encodeMetadata , METADATA_HEADER_INTERNAL } from './metadata.ts'
@@ -21,6 +23,10 @@ export enum Operation {
21
23
SET = 'set' ,
22
24
}
23
25
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
+
24
30
interface BlobsServerOptions {
25
31
/**
26
32
* Whether debug-level information should be logged, such as internal errors
@@ -271,12 +277,7 @@ export class BlobsServer {
271
277
const tempDataPath = join ( tempDirectory , relativeDataPath )
272
278
273
279
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 ) )
280
281
281
282
await fs . mkdir ( dirname ( dataPath ) , { recursive : true } )
282
283
await fs . copyFile ( tempDataPath , dataPath )
0 commit comments