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

Various small improvements #32

Merged
merged 3 commits into from Dec 11, 2017
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
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
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
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
@@ -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