Skip to content

Commit 0cc09f0

Browse files
committed
cork例子
1 parent 9152915 commit 0cc09f0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var fs = require('fs');
2+
var dest = fs.createWriteStream('./dest.txt', {flags: 'w'});
3+
4+
var max = 16 * 1024;
5+
var buff1 = Buffer.from('a'.repeat(max));
6+
var buff2 = Buffer.from('b'.repeat(max));
7+
8+
dest.cork();
9+
10+
var ret1 = dest.write(buff1);
11+
console.log(ret1);
12+
13+
var ret2 = dest.write(buff2);
14+
console.log(ret2);
15+
16+
dest.uncork(); // 备注:如果注释掉这行代码,内容不会写到 dest.txt 里
Binary file not shown.

0 commit comments

Comments
 (0)