Is the "onEnd" callback mandatory?
See original GitHub issueI have a use-case where I want to essentially pull the stream out of these callbacks before I use it.
return new Promise((resolve, reject) => {
req.multipart(
(field, filestream, originalFilename, encoding) => {
resolve(filestream);
},
(err?: Error) => {
// i don't care what happens here, i handle it elsewhere
},
{
limits: {
fileSize: TWO_MEGABYTES,
fields: 0,
files: 1,
},
},
);
}
I’m trying to figure out if I have to worry about the onEnd call back as it just seems really verbose. I’d rather get access to the file that’s being uploaded and resolve/pipe it somewhere else and handle the errors there. As it looks now, it appears I can do that but also need to handle a seemingly arbitrary case around the onEnd callback. Usually I notice the events happen in the following order, but I’m wondering if under certain circumstances that could change:
- resolve / pipe the file somewhere else
- initiate a pipe or a read on the file in it’s new location (ie passed to another function somewhere else, for example trigger a stream upload to a blob storage)
- the onEnd callback fires at somepoint.
I’m basically trying to see is there anything that can happen in step 3 that I wouldn’t be able to reasonably handle during step 2 in a different place? If so, it would be nice to figure out a clean way to make a promise implementation here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
That will work.
Oh, I understand.
Who is the streamwriter? Does it implement all the stream lifecycle?