diff --git a/lib/resource/virtualStored/VirtualStoredFile.js b/lib/resource/virtualStored/VirtualStoredFile.js index 515c8c57..06f7dafc 100644 --- a/lib/resource/virtualStored/VirtualStoredFile.js +++ b/lib/resource/virtualStored/VirtualStoredFile.js @@ -48,22 +48,18 @@ var VirtualStoredFile = (function (_super) { return; } var size = 0; - var wr = new stream_1.Writable({ - write: function (chunk, encoding, cb) { + var wr = new stream_1.Transform({ + transform: function (chunk, encoding, cb) { size += chunk.length; - return w.write(chunk, encoding, cb); + this.push(chunk); + cb(); } }); wr.on('finish', function () { _this.updateLastModified(); _this.len = size; }); - function emit(name) { - wr.on(name, function (_1, _2) { return w.emit(name, _1, _2); }); - } - emit('close'); - emit('error'); - emit('finish'); + wr.pipe(w); callback(null, wr); }); }; diff --git a/src/resource/virtualStored/VirtualStoredFile.ts b/src/resource/virtualStored/VirtualStoredFile.ts index 2d9d00f7..c44b6488 100644 --- a/src/resource/virtualStored/VirtualStoredFile.ts +++ b/src/resource/virtualStored/VirtualStoredFile.ts @@ -1,5 +1,5 @@ import { IResource, SimpleCallback, ReturnCallback, ResourceType } from '../IResource' -import { Readable, Writable } from 'stream' +import { Readable, Writable, Transform } from 'stream' import { VirtualStoredResource } from './VirtualStoredResource' import { FSManager } from '../../manager/FSManager' import { VirtualStoredFSManager } from '../../manager/VirtualStoredFSManager' @@ -55,10 +55,12 @@ export class VirtualStoredFile extends VirtualStoredResource let size = 0; - const wr = new Writable({ - write: (chunk, encoding, cb) => { + const wr = new Transform({ + transform(chunk, encoding, cb) + { size += chunk.length; - return w.write(chunk, encoding, cb); + this.push(chunk); + cb(); } }); wr.on('finish', () => { @@ -66,13 +68,7 @@ export class VirtualStoredFile extends VirtualStoredResource this.len = size; }) - function emit(name : string) - { - wr.on(name, (_1, _2) => w.emit(name, _1, _2)); - } - emit('close'); - emit('error'); - emit('finish'); + wr.pipe(w); callback(null, wr); });