Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement transforms & Update to a newer version of file-type #201

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Refactor autoContentType function to use
stream.pipeline
  • Loading branch information
halimsamy committed Dec 4, 2023
commit 2011a5912c5a32eb2ab0d2f52ce67c00547e36fb
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ function autoContentType (req, file, cb) {
return svgRegex.test(svg)
}

var outStream = new stream.PassThrough()

stream.pipeline(file.stream, outStream, function (err) {
if (err) return cb(err)
})

file.stream.once('data', function (firstChunk) {
fileType.fromBuffer(firstChunk).then(function (type) {
var mime = 'application/octet-stream' // default type
Expand All @@ -70,11 +76,6 @@ function autoContentType (req, file, cb) {
mime = type.mime
}

var outStream = new stream.PassThrough()

outStream.write(firstChunk)
file.stream.pipe(outStream)

cb(null, mime, outStream)
})
})
Expand Down