Skip to content

Commit

Permalink
v0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Llamas committed Dec 11, 2012
1 parent aa00de6 commit d9382cf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
5 changes: 4 additions & 1 deletion CHANGES
@@ -1,4 +1,7 @@
v0.2.2 (10 Dec 2012)
v0.2.3 (11 Dec 2012)
Replaces "errno-codes" dependency by "error-provider".

v0.2.2 (11 Dec 2012)
Added "mode" and "start" to the "open()" parameters.
Added "writeln()".
Added "flush()".
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@ _Node.js project_

#### Writes buffered data ####

Version: 0.2.2
Version: 0.2.3

Node.js streams are not buffered, that is, when you write data to them you're doing multiple I/O calls. This module buffers the data that has to be written to disk and eases the buffer manipulation when you need to write data from different nature (strings, numbers, arrays or buffers).

Expand Down
22 changes: 11 additions & 11 deletions buffered-writer.js
Expand Up @@ -2,16 +2,16 @@

var EVENTS = require ("events");
var FS = require ("fs");
var errno = require ("errno-codes");
var ep = require ("error-provider");

errno.create (errno.getNextAvailableErrno (), "INVALID_BUFFER_SIZE",
ep.create (ep.next (), "INVALID_BUFFER_SIZE",
"The buffer size must be greater than 0.");
errno.create (errno.getNextAvailableErrno (), "STREAM_CLOSED",
ep.create (ep.next (), "STREAM_CLOSED",
"The stream is already closed, cannot write nor close it again.");
errno.create (errno.getNextAvailableErrno (), "INVALID_OFFSET_LENGTH",
ep.create (ep.next (), "INVALID_OFFSET_LENGTH",
"The offset or length parameters are not valid (offset={offset}, " +
"length={length}, length-offset<0).");
errno.create (errno.getNextAvailableErrno (), "INVALID_DATA",
ep.create (ep.next (), "INVALID_DATA",
"The data can only be a Number, String, Array or Buffer");

var BUFFER_SIZE = 16384;
Expand All @@ -27,7 +27,7 @@ bw.open = function (file, args){

if (args.bufferSize === 0) args.bufferSize = -1;
args.bufferSize = args.bufferSize || BUFFER_SIZE;
if (args.bufferSize < 1) throw errno.get ("INVALID_BUFFER_SIZE");
if (args.bufferSize < 1) throw ep.get ("INVALID_BUFFER_SIZE");

return new Writer (file, args);
};
Expand Down Expand Up @@ -103,7 +103,7 @@ Writer.prototype._write = function (data, offset, length){

Writer.prototype.close = function (cb){
if (this._closed){
return this._error (errno.get ("STREAM_CLOSED"));
return this._error (ep.get ("STREAM_CLOSED"));
}

if (this._offset){
Expand All @@ -129,7 +129,7 @@ Writer.prototype.flush = function (cb){

Writer.prototype.line = function (){
if (this._closed){
return this._error (errno.get ("STREAM_CLOSED"));
return this._error (ep.get ("STREAM_CLOSED"));
}
this._write (EOL, 0, EOL.length);
return this;
Expand All @@ -146,7 +146,7 @@ var toHexArray = function (n){

Writer.prototype.write = function (buffer, offset, length){
if (this._closed){
return this._error (errno.get ("STREAM_CLOSED"));
return this._error (ep.get ("STREAM_CLOSED"));
}

offset = offset || 0;
Expand All @@ -171,15 +171,15 @@ Writer.prototype.write = function (buffer, offset, length){
}else{
var me = this;
this.close (function (){
me._error (errno.get ("INVALID_DATA"));
me._error (ep.get ("INVALID_DATA"));
});
return;
}

if (stringError || length < 0){
var me = this;
this.close (function (){
me._error (errno.get ("INVALID_OFFSET_LENGTH", {
me._error (ep.get ("INVALID_OFFSET_LENGTH", {
offset: offset,
length: length
}));
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "buffered-writer",
"version": "0.2.2",
"version": "0.2.3",
"description": "Writes buffered data to files",
"keywords": ["buffer", "write", "stream", "file", "binary", "data"],
"author": {
Expand All @@ -15,7 +15,7 @@
"node": "*"
},
"dependencies": {
"errno-codes": "*"
"error-provider": "*"
},
"licenses": [{
"type": "MIT",
Expand Down

0 comments on commit d9382cf

Please sign in to comment.