该程序使用pipe()流类提供的功能使用可读和可写流复制文件
// 需要文件系统模块 var fs = require('fs'); /* Create readable stream to file in current directory named 'node.txt' Use utf8 encoding Read the data in 16-kilobyte chunks */ var readable = fs.createReadStream(__dirname + '/node.txt', { encoding: 'utf8', highWaterMark: 16 * 1024 }); // 创建可写流 var writable = fs.createWriteStream(__dirname + '/nodePipe.txt'); // 使用管道将可读复制为可写 readable.pipe(writable);