(self, fileStream)
| 695 | } |
| 696 | |
| 697 | function 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 | |
| 746 | function handleField(self, fieldStream) { |
| 747 | var value = ''; |
no test coverage detected
searching dependent graphs…