Skip to content

Instantly share code, notes, and snippets.

@heapwolf heapwolf/54.js
Created Aug 7, 2012

Embed
What would you like to do?
fs/close
var fs = require('fs');
function openAndWriteToSystemLog(writeBuffer, callback) {
fs.open('/var/log/system.log', 'a', function opened(err, fd) {
if (err) { return callback(err); }
function notifyError(err) {
fs.close(fd, function() {
callback(err);
});
}
var bufferOffset = 0,
bufferLength = writeBuffer.length, filePosition = null;
fs.write( fd, writeBuffer, bufferOffset, bufferLength, filePosition, function wrote(err, written) {
if (err) { return notifyError(err); }
fs.close(fd, function() {
callback(err);
});
});
});
@heapwolf

This comment has been minimized.

Copy link
Owner Author

heapwolf commented Aug 7, 2012

openAndWriteToSystemLog(
new Buffer('writing this string'),
function done(err) {
if (err) {
console.log("error while opening and writing:", err.message);
return;
}
console.log('All done with no errors');
}
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.