| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 897b1d2 commit 7eed9d6
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -300,6 +300,11 @@ function WriteStream(path, options) { | |||
| 300 | 300 | options.emitClose = false; | |
| 301 | 301 | } | |
| 302 | 302 | ||
| 303 | + if (options.autoDestroy === undefined) { | ||
| 304 | + options.autoDestroy = options.autoClose === undefined ? | ||
| 305 | + true : (options.autoClose || false); | ||
| 306 | + } | ||
| 307 | + | ||
| 303 | 308 | this[kFs] = options.fs || fs; | |
| 304 | 309 | if (typeof this[kFs].open !== 'function') { | |
| 305 | 310 | throw new ERR_INVALID_ARG_TYPE('options.fs.open', 'function', | |
@@ -343,7 +348,7 @@ function WriteStream(path, options) { | |||
| 343 | 348 | this.mode = options.mode === undefined ? 0o666 : options.mode; | |
| 344 | 349 | ||
| 345 | 350 | this.start = options.start; | |
| 346 | - this.autoClose = options.autoClose === undefined ? true : !!options.autoClose; | ||
| 351 | + this.autoClose = options.autoDestroy; | ||
| 347 | 352 | this.pos = undefined; | |
| 348 | 353 | this.bytesWritten = 0; | |
| 349 | 354 | this.closed = false; | |
@@ -371,10 +376,6 @@ WriteStream.prototype._final = function(callback) { | |||
| 371 | 376 | }); | |
| 372 | 377 | } | |
| 373 | 378 | ||
| 374 | - if (this.autoClose) { | ||
| 375 | - this.destroy(); | ||
| 376 | - } | ||
| 377 | - | ||
| 378 | 379 | callback(); | |
| 379 | 380 | }; | |
| 380 | 381 | ||
@@ -425,9 +426,6 @@ WriteStream.prototype._write = function(data, encoding, cb) { | |||
| 425 | 426 | } | |
| 426 | 427 | ||
| 427 | 428 | if (er) { | |
| 428 | - if (this.autoClose) { | ||
| 429 | - this.destroy(); | ||
| 430 | - } | ||
| 431 | 429 | return cb(er); | |
| 432 | 430 | } | |
| 433 | 431 | this.bytesWritten += bytes; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | - require('../common'); | ||
| 23 | + const common = require('../common'); | ||
| 24 | 24 | const assert = require('assert'); | |
| 25 | 25 | ||
| 26 | 26 | const path = require('path'); | |
@@ -46,9 +46,9 @@ file | |||
| 46 | 46 | callbacks.open++; | |
| 47 | 47 | assert.strictEqual(typeof fd, 'number'); | |
| 48 | 48 | }) | |
| 49 | - .on('error', function(err) { | ||
| 50 | - throw err; | ||
| 51 | - }) | ||
| 49 | + .on('error', common.mustCall((err) => { | ||
| 50 | + assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END'); | ||
| 51 | + })) | ||
| 52 | 52 | .on('drain', function() { | |
| 53 | 53 | console.error('drain!', callbacks.drain); | |
| 54 | 54 | callbacks.drain++; | |
@@ -61,21 +61,12 @@ file | |||
| 61 | 61 | } | |
| 62 | 62 | }) | |
| 63 | 63 | .on('close', function() { | |
| 64 | - console.error('close!'); | ||
| 65 | 64 | assert.strictEqual(file.bytesWritten, EXPECTED.length * 2); | |
| 66 | 65 | ||
| 67 | 66 | callbacks.close++; | |
| 68 | - assert.throws( | ||
| 69 | - () => { | ||
| 70 | - console.error('write after end should not be allowed'); | ||
| 71 | - file.write('should not work anymore'); | ||
| 72 | - }, | ||
| 73 | - { | ||
| 74 | - code: 'ERR_STREAM_WRITE_AFTER_END', | ||
| 75 | - name: 'Error', | ||
| 76 | - message: 'write after end' | ||
| 77 | - } | ||
| 78 | - ); | ||
| 67 | + file.write('should not work anymore', common.mustCall((err) => { | ||
| 68 | + assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END'); | ||
| 69 | + })); | ||
| 79 | 70 | ||
| 80 | 71 | fs.unlinkSync(fn); | |
| 81 | 72 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const fs = require('fs'); | ||
| 5 | + const path = require('path'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const tmpdir = require('../common/tmpdir'); | ||
| 8 | + const writeFile = path.join(tmpdir.path, 'write-autoClose.txt'); | ||
| 9 | + tmpdir.refresh(); | ||
| 10 | + | ||
| 11 | + const file = fs.createWriteStream(writeFile, { autoClose: true }); | ||
| 12 | + | ||
| 13 | + file.on('finish', common.mustCall(() => { | ||
| 14 | + assert.strictEqual(file.destroyed, false); | ||
| 15 | + })); | ||
| 16 | + file.end('asd'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,8 +27,8 @@ function next() { | |||
| 27 | 27 | stream.end(); | |
| 28 | 28 | stream.on('finish', common.mustCall(function() { | |
| 29 | 29 | assert.strictEqual(stream.closed, false); | |
| 30 | - assert.strictEqual(stream.fd, null); | ||
| 31 | 30 | stream.on('close', common.mustCall(function() { | |
| 31 | + assert.strictEqual(stream.fd, null); | ||
| 32 | 32 | assert.strictEqual(stream.closed, true); | |
| 33 | 33 | process.nextTick(next2); | |
| 34 | 34 | })); | |
@@ -51,8 +51,8 @@ function next3() { | |||
| 51 | 51 | stream.end(); | |
| 52 | 52 | stream.on('finish', common.mustCall(function() { | |
| 53 | 53 | assert.strictEqual(stream.closed, false); | |
| 54 | - assert.strictEqual(stream.fd, null); | ||
| 55 | 54 | stream.on('close', common.mustCall(function() { | |
| 55 | + assert.strictEqual(stream.fd, null); | ||
| 56 | 56 | assert.strictEqual(stream.closed, true); | |
| 57 | 57 | })); | |
| 58 | 58 | })); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments