node

作者: jmtjt | 来源:发表于2019-07-04 23:00 被阅读0次

    fs

    const fs = require('fs');

    const data = fs.readFileSync('conf.js');//阻塞操作

    console.log(data)

    fs.readFile('./conf.js', (err, data) => {  //异步操作

        console.log(data)

    });

    //Promise

    const { promisify } = require('util');

    const readFile = promisify(fs.readFile);

    readFile('./conf.js').then(data => console.log(data))

    //实验警告

    const { promises } = require('fs');

    promises.readFile('./conf.js').then(data => console.log(data))



    const fs = require('fs');

    const rs= fs.createReadStream('./conf.js') // 读取流

    const ws = fs.createWriteStream('./conf2.js') // 写入流

    rs.pipe(ws);会重新创建一个js 复制


    buffer 

    const buf1 = Buffer.alloc(10);

    console.log(buf1)

    const buf2 = Buffer.from([1,2,3])

    console.log(buf2)

    //写入

    buf1.write('hello')

    console.log(buf1)

    //读取

    console.log(buf1.toString())

    const buf4 = Buffer.concat([buf1,buf2])

    console.log(buf4.toString())

    相关文章

      网友评论

          本文标题:node

          本文链接:https://www.haomeiwen.com/subject/xxdzxctx.html