Skip to content

Commit

Permalink
split streams when creating write stream
Browse files Browse the repository at this point in the history
  • Loading branch information
ricsam committed May 13, 2020
1 parent a3fea3e commit e0db24a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/nafs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,20 @@ const activeStorageS3Serve: NAFSFactory = (url) => {

const createWriteStream = (fpath: string) => {
const ptStream = new stream.PassThrough();
const s3Stream = new stream.PassThrough();
const cacheStream = new stream.PassThrough();
ptStream.pipe(s3Stream);
ptStream.pipe(cacheStream);
s3.upload({
Bucket: bucket,
Key: getS3Path(fpath),
Body: ptStream,
Body: s3Stream,
}, (err) => {
if (err) {
throw err;
}
});
writeStreamToCache(fpath, ptStream);
writeStreamToCache(fpath, cacheStream);
return ptStream;
};

Expand Down

0 comments on commit e0db24a

Please sign in to comment.