wrote
![npm version](https://badge.fury.io/js/wrote.svg)
Promise-based write for Node.js
wrote(filepath?:String) => Promise<Writable> (ws.writable == true)
Create a write stream to your file without hastle.
const Writable = require('stream').Writable
const path = require('path')
const wrote = require('./')
const HOME_DIR = require('os').homedir()
const file = path.join(HOME_DIR, `wrote-${Math.floor(Math.random() * 1e5)}.data`)
return wrote(file)
.then((ws) => {
console.log(ws instanceof Writable)
console.log(ws.path)
})
.catch(console.error)
If you don't have a file, a new one in the temp directory will be created for you.
const wrote = require('wrote')
const Writable = require('stream').Writable
return wrote()
.then((ws) => {
console.log(ws instanceof Writable)
console.log(ws.path)
})
.catch(console.error)
wrote.erase(ws:Writable) => Promise<Writable> (ws.writable == false)
Erase file and close stream.
const wrote = require('wrote')
const Writable = require('stream').Writable
const path = require('path')
const HOME_DIR = require('os').homedir()
const fs = require('fs')
const file = path.join(HOME_DIR, `wrote-${Math.floor(Math.random() * 1e5)}.data`)
return wrote(file)
.then((ws) => {
console.log(ws instanceof Writable)
console.log(ws.writable)
console.log(ws.path)
return wrote.erase(ws)
})
.then((ws) => {
console.log(ws.path)
console.log(ws.writable)
})
.catch(console.error)
todo
- pass random function generator
Licence: MIT
(c) Sobesednik-Media 2017