Skip to content

Commit

Permalink
Auto-merge for PR #32 via VersionBot
Browse files Browse the repository at this point in the history
Various small improvements
  • Loading branch information
resin-io-modules-versionbot[bot] committed Dec 11, 2017
2 parents c05a346 + 0dcfbda commit 7b83269
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).

## v4.1.1 - 2017-12-11

* Refactor read stream logic to improve clarity & error handling #32 [Tim Perry]
* Update Bluebird to v3 #32 [Tim Perry]

## v4.1.0 - 2017-11-21

* Upgrade partitioninfo so we can read GPT partition tables too #31 [Tim Perry]
Expand Down
20 changes: 13 additions & 7 deletions build/imagefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,24 @@ read = function(disk, partition, path) {
readStream = null;
outputStream = new stream.PassThrough();
startReadStream = function() {
outputStream.removeListener('newListener', startReadStream);
return process.nextTick(function() {
var e;
try {
readStream = fs_.createReadStream(path, {
autoClose: false
});
readStream.on('error', function(err) {
return outputStream.emit('error', err);
});
return readStream.pipe(outputStream);
} catch (_error) {
e = _error;
outputStream.emit('error', e);
return;
}
readStream.on('error', function(err) {
return outputStream.emit('error', err);
});
return readStream.pipe(outputStream);
};
outputStream.on('newListener', startReadStream);
outputStream.once('newListener', function() {
return process.nextTick(startReadStream);
});
return Promise.resolve(outputStream).disposer(function(stream) {
outputStream.end();
if ((readStream != null) && readStream.closeAsync) {
Expand Down
21 changes: 12 additions & 9 deletions lib/imagefs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ read = (disk, partition, path) ->
readStream = null
outputStream = new stream.PassThrough()

# We don't start the stream until somebody else starts listening
startReadStream = ->
outputStream.removeListener('newListener', startReadStream)

# This is triggered _before_ the listener is added, so wait briefly
process.nextTick ->
try
readStream = fs_.createReadStream(path, autoClose: false)
readStream.on 'error', (err) ->
outputStream.emit('error', err)
readStream.pipe(outputStream)
catch e
outputStream.emit('error', e)
return

readStream.on 'error', (err) ->
outputStream.emit('error', err)

outputStream.on('newListener', startReadStream)
readStream.pipe(outputStream)

# We don't start the stream until somebody else starts listening
# Delayed slightly, as this event fires _before_ the listener is added
outputStream.once('newListener', -> process.nextTick(startReadStream))

Promise.resolve(outputStream)
.disposer (stream) ->
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resin-image-fs",
"version": "4.1.0",
"version": "4.1.1",
"description": "Resin.io image filesystem manipulation utilities",
"main": "build/imagefs.js",
"homepage": "https://github.com/resin-io/resin-image-fs",
Expand Down Expand Up @@ -44,7 +44,7 @@
"wary": "^1.0.0"
},
"dependencies": {
"bluebird": "^2.9.32",
"bluebird": "^3.5.1",
"ext2fs": "^0.1.0",
"fatfs": "^0.10.6",
"file-disk": "^1.0.1",
Expand Down

0 comments on commit 7b83269

Please sign in to comment.