Skip to content

Commit

Permalink
add .stream()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Aug 2, 2014
1 parent 039209d commit f5bd0e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ You may want to serve the smallest of `data.length['.min.js.gz']`
and `data.length['.min.js']` if you like to over-optimize.
You also probably don't need to stringify the buffer to send it to the client.

### ecstacy.stream(name, extension)

Create a read stream for a file and extension instead of buffering it.
Useful when serving files to the client.

### ecstacy.minify(name).then( => )

Minify the asset and add its content length to `data.length`.
Expand Down
5 changes: 5 additions & 0 deletions lib/ecstacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ function reject(err) {
if (err.code !== 'ENOENT') throw err
}

Ecstacy.stream =
Ecstacy.prototype.stream = function (name, ext) {
return fs.createReadStream(path.join(Ecstacy.folder, name + ext))
}

// write a file to the cache
Ecstacy.write =
Ecstacy.prototype.write = function (name, ext, data) {
Expand Down
7 changes: 7 additions & 0 deletions test/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ describe('Ecstacy.js(code, map)', function () {
return ecstacy.read(data.name, '.min.js.gz')
})
})

it('.stream(name, .min.js.gz)', function (done) {
var stream = ecstacy.stream(data.name, '.min.js.gz')
stream.resume()
stream.once('end', done)
stream.once('error', done)
})
})

describe('es5', function () {
Expand Down

0 comments on commit f5bd0e0

Please sign in to comment.