Skip to content

Commit

Permalink
fix: simplify streaming of server writes
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Jan 15, 2024
1 parent 3fdde97 commit da3f42f
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import http from 'node:http'
import { tmpdir } from 'node:os'
import { dirname, join, relative, resolve, sep } from 'node:path'
import { platform } from 'node:process'
import { promises as stream } from 'node:stream'

import { ListResponse } from './backend/list.ts'
import { decodeMetadata, encodeMetadata, METADATA_HEADER_INTERNAL } from './metadata.ts'
Expand Down Expand Up @@ -271,12 +272,7 @@ export class BlobsServer {
const tempDataPath = join(tempDirectory, relativeDataPath)

await fs.mkdir(dirname(tempDataPath), { recursive: true })

await new Promise((resolve, reject) => {
req.pipe(createWriteStream(tempDataPath))
req.on('end', resolve)
req.on('error', reject)
})
await stream.pipeline(req, createWriteStream(tempDataPath))

await fs.mkdir(dirname(dataPath), { recursive: true })
await fs.copyFile(tempDataPath, dataPath)
Expand Down

0 comments on commit da3f42f

Please sign in to comment.