MCPcopy Create free account
hub / github.com/pillarjs/multiparty / handleFile

Function handleFile

index.js:697–744  ·  view source on GitHub ↗
(self, fileStream)

Source from the content-addressed store, hash-verified

695}
696
697function handleFile(self, fileStream) {
698 if (self.error) return;
699 var publicFile = {
700 fieldName: fileStream.name,
701 originalFilename: fileStream.filename,
702 path: uploadPath(self.uploadDir, fileStream.filename),
703 headers: fileStream.headers,
704 size: 0
705 };
706 var internalFile = {
707 publicFile: publicFile,
708 ls: null,
709 ws: fs.createWriteStream(publicFile.path, { flags: 'wx' })
710 };
711 self.openedFiles.push(internalFile)
712 beginFlush(self); // flush to write stream
713 var emitAndReleaseHold = holdEmitQueue(self, fileStream);
714 fileStream.on('error', function(err) {
715 self.handleError(err);
716 });
717 internalFile.ws.on('error', function (err) {
718 self.handleError(err)
719 })
720 internalFile.ws.on('open', function () {
721 // end option here guarantees that no more than that amount will be written
722 // or else an error will be emitted
723 internalFile.ls = new LimitStream(self.maxFilesSize - self.totalFileSize)
724 internalFile.ls.pipe(internalFile.ws)
725
726 internalFile.ls.on('error', function (err) {
727 self.handleError(err.code === 'ETOOBIG'
728 ? createError(413, err.message, { code: err.code })
729 : err)
730 });
731 internalFile.ls.on('progress', function (totalBytes, chunkBytes) {
732 publicFile.size = totalBytes
733 self.totalFileSize += chunkBytes
734 });
735 internalFile.ws.on('close', function () {
736 if (self.error) return;
737 emitAndReleaseHold(function() {
738 self.emit('file', fileStream.name, publicFile);
739 });
740 endFlush(self);
741 });
742 fileStream.pipe(internalFile.ls)
743 });
744}
745
746function handleField(self, fieldStream) {
747 var value = '';

Callers 1

index.jsFile · 0.85

Calls 4

uploadPathFunction · 0.85
beginFlushFunction · 0.85
holdEmitQueueFunction · 0.85
endFlushFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…