Skip to content

Commit 45ebc70

Browse files
committed
fix write buffer issue.
1 parent 607b986 commit 45ebc70

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lib/Writer.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ export default function Writer (stream)
44
{
55
function writer (data)
66
{
7-
data = tr(data, writer.transforms)
8-
9-
tr_ed = true
10-
117
try
128
{
9+
data = tr(data, writer.transforms)
10+
tr_ed = true
11+
1312
stream.write(data + '\n')
1413
}
1514
finally
@@ -36,10 +35,8 @@ export default function Writer (stream)
3635
{
3736
if (! tr_ed)
3837
{
39-
/* encoding is ignored; TODO? */
40-
var chunk = String(args[0])
41-
42-
args[0] = tr(chunk, writer.transforms)
38+
/* TODO: consider encoding */
39+
args[0] = tr(args[0], writer.transforms)
4340
}
4441

4542
$write.apply(stream, args)
@@ -54,14 +51,14 @@ export default function Writer (stream)
5451

5552
function tr (data, transforms)
5653
{
57-
data = String(data)
54+
if (typeof data !== 'string')
55+
{
56+
return data
57+
}
5858

59-
if (transforms.length)
59+
for (let n = transforms.length; n; n--)
6060
{
61-
for (let n = transforms.length; n; n--)
62-
{
63-
data = transforms[n - 1](data)
64-
}
61+
data = transforms[n - 1](data)
6562
}
6663

6764
return data

test/stream.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import Console from 'console-ultimate/Console'
3+
4+
describe('stream', () =>
5+
{
6+
Console()
7+
8+
it('print buffer', () =>
9+
{
10+
process.stdout.write(Buffer.from('\n'))
11+
})
12+
})

0 commit comments

Comments
 (0)