Skip to content

Commit

Permalink
fix: do not use stream/promises as it is not supported in older versi…
Browse files Browse the repository at this point in the history
…on of node
  • Loading branch information
thetutlage committed Jun 6, 2023
1 parent 261d69e commit 6162d97
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Multipart/streamFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* file that was distributed with this source code.
*/

import { Readable } from 'stream'
import { promisify } from 'util'
import { unlink } from 'fs-extra'
import { createWriteStream } from 'fs'
import { pipeline } from 'stream/promises'
import { Readable, pipeline } from 'stream'

const pump = promisify(pipeline)

/**
* Writes readable stream to the given location by properly cleaning up readable
Expand All @@ -29,7 +31,7 @@ export async function streamFile(

const writeStream = createWriteStream(location)
try {
await pipeline(readStream, writeStream)
await pump(readStream, writeStream)
} catch (error) {
unlink(writeStream.path).catch(() => {})
throw error
Expand Down

0 comments on commit 6162d97

Please sign in to comment.