Skip to content

Latest commit

 

History

History
73 lines (60 loc) · 1.52 KB

README_CH.md

File metadata and controls

73 lines (60 loc) · 1.52 KB

RxfileWrite

To -> EN

Node.js -> fs: 简单使用工具

npm i rxfile-write --save-dev
  1. 确定 文件/目录 是否存在
  2. 阅读文件中的所有内容
  3. 擦除将内容写入文件, 或 将内容添加到文件
  4. 删除 文件/目录

使用

  // node / cjs
  const RxfileWrite = require('rxfile-write')
  // or
  import RxfileWrite from 'rxfile-write'
  const path = require('path')

  function ps (p) {
    return path.resolve(__dirname, '..', p)
  }

  // - - RxfileWrite.read 读内容- -
  RxfileWrite.read(ps('LICENSE')).then(data => {
    console.log('data\n\n', data)
  }).catch(err => {
    console.log('read error=', err)
  })

  // - - RxfileWrite.exists 判断是否存在- -
  RxfileWrite.exists(ps('LICENSE')).then(() => {
    console.log('exists is ok')
  }).catch(err => {
    console.log('exists error=', err)
  })

  // - - RxfileWrite.write 写 - -
  RxfileWrite.write(ps('ttt.txt'), 'hello world!').then(() => {
    console.log('write succ')

    setTimeout(() => {
      // - - RxfileWrite.remove 删除 - -
      RxfileWrite.remove(ps('ttt.txt')).then(() => {
        console.log('remove succ')
      }).catch(err => {
        console.log('remove error=', err)
      })
    }, 5000);

  }).catch(err => {
    console.log('write error=', err)
  })

api

  1. exists
  2. read
  3. cp
  4. cpSync
  5. write
  6. writeSync
  7. writeAppend
  8. writeAppendSync
  9. writeTo
  10. remove

License

MIT