fs: use proper .destroy() implementation for SyncWriteStream · nodejs/node@abafd38 (original) (raw)

`@@ -19,7 +19,6 @@ const filename = path.join(tmpdir.path, 'sync-write-stream.txt');

`

19

19

`assert.strictEqual(stream.fd, 1);

`

20

20

`assert.strictEqual(stream.readable, false);

`

21

21

`assert.strictEqual(stream.autoClose, true);

`

22

``

`-

assert.strictEqual(stream.listenerCount('end'), 1);

`

23

22

`}

`

24

23

``

25

24

`// Verify constructing the instance with specified options.

`

`@@ -29,7 +28,6 @@ const filename = path.join(tmpdir.path, 'sync-write-stream.txt');

`

29

28

`assert.strictEqual(stream.fd, 1);

`

30

29

`assert.strictEqual(stream.readable, false);

`

31

30

`assert.strictEqual(stream.autoClose, false);

`

32

``

`-

assert.strictEqual(stream.listenerCount('end'), 1);

`

33

31

`}

`

34

32

``

35

33

`// Verify that the file will be written synchronously.

`

`@@ -47,21 +45,28 @@ const filename = path.join(tmpdir.path, 'sync-write-stream.txt');

`

47

45

`const fd = fs.openSync(filename, 'w');

`

48

46

`const stream = new SyncWriteStream(fd);

`

49

47

``

50

``

`-

stream.on('close', common.mustCall(3));

`

``

48

`+

stream.on('close', common.mustCall());

`

``

49

`+

assert.strictEqual(stream.destroy(), stream);

`

``

50

`+

assert.strictEqual(stream.fd, null);

`

``

51

`+

}

`

``

52

+

``

53

`+

// Verify that the stream will unset the fd after destroySoon().

`

``

54

`+

{

`

``

55

`+

const fd = fs.openSync(filename, 'w');

`

``

56

`+

const stream = new SyncWriteStream(fd);

`

51

57

``

52

``

`-

assert.strictEqual(stream.destroy(), true);

`

``

58

`+

stream.on('close', common.mustCall());

`

``

59

`+

assert.strictEqual(stream.destroySoon(), stream);

`

53

60

`assert.strictEqual(stream.fd, null);

`

54

``

`-

assert.strictEqual(stream.destroy(), true);

`

55

``

`-

assert.strictEqual(stream.destroySoon(), true);

`

56

61

`}

`

57

62

``

58

``

`-

// Verify that the 'end' event listener will also destroy the stream.

`

``

63

`+

// Verify that calling end() will also destroy the stream.

`

59

64

`{

`

60

65

`const fd = fs.openSync(filename, 'w');

`

61

66

`const stream = new SyncWriteStream(fd);

`

62

67

``

63

68

`assert.strictEqual(stream.fd, fd);

`

64

69

``

65

``

`-

stream.emit('end');

`

``

70

`+

stream.end();

`

66

71

`assert.strictEqual(stream.fd, null);

`

67

72

`}

`