by
25
8
4,311
1
Top 1% !
Popular
Famous
Nice
Useful
Easy-to-find
Specified
MultiPlatform
Popularity: 2164th place
Languagehttp
Languagejavascript
LicenseMIT_X11

Scribbles.js

A non-blocking, thread-safe, async file-writer / appender for node.js....  
oh yeah, its also faster than grease. Try iT!
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/238251/Scribbles-js?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// scribbles.js var fs = require('fs'), path = require('path'), scribe = null, canWrite = true, roster = [], scribblesQue = {}; function Scribbles(file) { this.fPath = file; this.react = null; } scribe = Scribbles.prototype; scribe.scribble = function(data, reaction) { var proceed = function () { canWrite = true; if (proceed) { var dta = proceed; proceed = null; scribble(dta); } }, react = function(err, data, proceed) { if (err) { throw err; } proceed(); }, assign = function(reaction) { this.react = reaction; return this; }; if (!this.canWrite) { proceed = data; if (reaction) { this.roster.push(reaction); } return this; } else { var lazyfunc = null, slf = this; canWrite = false; fs.appendFile(slf.fPath, data, function(err) { proceed(); react(err, data, proceed); while (lazyfunc = roster.shift()) { lazyfunc(err); } if (reaction){ reaction(err); } }); } return this; }; module.exports = function(fileName) { var fnm = path.resolve(fileName); return scribblesQue[fnm] = scribblesQue[fnm] || new Scribbles(fileName); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus