Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to transform file stream before sending it #171

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ unreleased
- deps: setprototypeof@1.1.0
- deps: statuses@'>= 1.3.1 < 2'
* deps: statuses@~1.5.0
* perf: remove redundant `path.normalize` call

0.16.2 / 2018-02-07
===================
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ SendStream.prototype.pipe = function pipe (res) {

// join / normalize from optional root dir
path = normalize(join(root, path))
root = normalize(root + sep)
} else {
// ".." is malicious without "root"
if (UP_PATH_REGEXP.test(path)) {
Expand Down Expand Up @@ -795,6 +794,15 @@ SendStream.prototype.stream = function stream (path, options) {

// pipe
var stream = fs.createReadStream(path, options)

// apply additional transformation streams if any
if (options.transformStreams) {
for(var i = 0; i < options.transformStreams.length; i++) {
var transform = options.transformStreams[i];
stream = stream.pipe(transform);
}
}

this.emit('stream', stream)
stream.pipe(res)

Expand Down