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

open() and copy() misbehave if the destination file is readonly #70

Open
ghost opened this issue Nov 19, 2013 · 0 comments
Open

open() and copy() misbehave if the destination file is readonly #70

ghost opened this issue Nov 19, 2013 · 0 comments
Assignees

Comments

@ghost
Copy link

ghost commented Nov 19, 2013

This seems to be happening because Writer(), in writer.js, is returning Q(self) instead of a deferred 'begin' promise, as Reader() does.

If I amend Writer, as below, using the open event, then it will work correctly for both writable and non-writable files (unit-tests pass). However, as far as I am aware HTTP streams do not emit the open event, so I'm not sure if this "fix" is the correct approach - happy to look at some other approach if anyone can offers hints.

(When using the open event in the Reader(), HTTP unit-tests fail, which confirms that reading HTTP streams does not emit the open event. Given that the unit-tests pass above, I assume writing HTTP streams via unit-tests is not done or does not invoke Writer().)

?

function Writer(_stream, charset) {
    var self = Object.create(Writer.prototype);

    if (charset && _stream.setEncoding) // TODO complain about inconsistency
        _stream.setEncoding(charset);

    var begin = Q.defer();
    var drained = Q.defer();

    _stream.on("error", function (reason) {
        begin.reject(reason);
    });

    _stream.on("open", function () {
        begin.resolve(self);
    });

    _stream.on("drain", function () {
        drained.resolve();
        drained = Q.defer();
    });

    :.............. (rest of code)................

    return begin.promise;
    //return Q(self); // todo returns the begin.promise
}
@ghost ghost assigned kriskowal May 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant