Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated BufferedWriter for tests

  • Loading branch information...
commit 3609d2d2d9450995df22c2e09223856e438f3f8c 1 parent 7c9b53e
@gagle authored
View
2  test/tests/node_modules/buffered-writer/buffered-writer.js
@@ -1 +1 @@
-"use strict";var EVENTS=require("events"),FS=require("fs"),BUFFER_SIZE=16384,EOL=process.platform.indexOf("win")!==-1?new Buffer([13,10]):new Buffer([10]),INVALID_BUFFER_SIZE=new Error("The buffer size must be greater than 0."),BufferedWriter=function(a,b){EVENTS.EventEmitter.call(this),b=b||{},b.bufferSize===0&&(b.bufferSize=-1),this._settings={bufferSize:b.bufferSize||BUFFER_SIZE,encoding:b.encoding||null,append:b.append?"a":"w"};if(this._settings.bufferSize<1)throw INVALID_BUFFER_SIZE;this._fileName=a,this._stream=null,this._buffer=null,this._bufferOffset=0};BufferedWriter.prototype=Object.create(EVENTS.EventEmitter.prototype),BufferedWriter.prototype.constructor=BufferedWriter,BufferedWriter.prototype._flush=function(){this._stream.write(new Buffer(this._bufferOffset!==this._settings.bufferSize?this._buffer.slice(0,this._bufferOffset):this._buffer)),this._bufferOffset=0},BufferedWriter.prototype._canWrite=function(a){return a+this._bufferOffset>this._settings.bufferSize&&(a=this._settings.bufferSize-this._bufferOffset),a},BufferedWriter.prototype._write=function(a,b,c){var d=this;this._stream||(this._buffer=new Buffer(this._settings.bufferSize),this._stream=FS.createWriteStream(this._fileName,{flags:d._settings.append}),this._stream.on("error",function(a){d.emit(a)}));var e=this._canWrite(c);a.copy(this._buffer,this._bufferOffset,b,b+e),this._bufferOffset+=e,b+=e,c-=e,this._bufferOffset===this._settings.bufferSize&&(this._flush(),c!==0&&this._write(a,b,c))},BufferedWriter.prototype.close=function(a){if(!this._stream)return;this._bufferOffset!==0&&this._flush();var b=this;this._stream.on("close",function(){a&&a.call(this)}),this._stream.destroySoon(),this._stream=null,this._buffer=null},BufferedWriter.prototype.newLine=function(){return this._write(EOL,0,EOL.length),this};var isArray=function(a){return Object.prototype.toString.call(a)==="[object Array]"},toHexArray=function(a){var b=[];do b.unshift(a&255),a>>>=8;while(a);return b};BufferedWriter.prototype.write=function(a,b,c){var d=typeof a;if(d==="number")b=0,a=toHexArray(a),c=a.length,a=new Buffer(a);else if(d==="string")b=0,c=Buffer.byteLength(a,this._settings.encoding),a=new Buffer(a,this._settings.encoding);else{isArray(a)&&(a=new Buffer(a));var e=arguments.length;e===1&&(b=0,c=1)}return this._write(a,b,c),this},module.exports=BufferedWriter;
+"use strict";var EVENTS=require("events"),FS=require("fs"),BUFFER_SIZE=16384,EOL=process.platform.indexOf("win")!==-1?new Buffer([13,10]):new Buffer([10]),INVALID_BUFFER_SIZE=new Error("The buffer size must be greater than 0."),BufferedWriter=function(a,b){EVENTS.EventEmitter.call(this),b=b||{},b.bufferSize===0&&(b.bufferSize=-1),this._settings={bufferSize:b.bufferSize||BUFFER_SIZE,encoding:b.encoding||null,append:b.append?"a":"w"};if(this._settings.bufferSize<1)throw INVALID_BUFFER_SIZE;this._fileName=a,this._stream=null,this._buffer=null,this._bufferOffset=0};BufferedWriter.prototype=Object.create(EVENTS.EventEmitter.prototype),BufferedWriter.prototype.constructor=BufferedWriter,BufferedWriter.prototype._flush=function(){this._stream.write(new Buffer(this._bufferOffset!==this._settings.bufferSize?this._buffer.slice(0,this._bufferOffset):this._buffer)),this._bufferOffset=0},BufferedWriter.prototype._canWrite=function(a){return a+this._bufferOffset>this._settings.bufferSize&&(a=this._settings.bufferSize-this._bufferOffset),a},BufferedWriter.prototype._write=function(a,b,c){var d=this;this._stream||(this._buffer=new Buffer(this._settings.bufferSize),this._stream=FS.createWriteStream(this._fileName,{flags:d._settings.append}),this._stream.on("error",function(a){d.emit("error",a)}));var e=this._canWrite(c);a.copy(this._buffer,this._bufferOffset,b,b+e),this._bufferOffset+=e,b+=e,c-=e,this._bufferOffset===this._settings.bufferSize&&(this._flush(),c!==0&&this._write(a,b,c))},BufferedWriter.prototype.close=function(a){if(!this._stream)return;this._bufferOffset!==0&&this._flush();var b=this;this._stream.on("close",function(){a&&a.call(this)}),this._stream.destroySoon(),this._stream=null,this._buffer=null},BufferedWriter.prototype.newLine=function(){return this._write(EOL,0,EOL.length),this};var isArray=function(a){return Object.prototype.toString.call(a)==="[object Array]"},toHexArray=function(a){var b=[];do b.unshift(a&255),a>>>=8;while(a);return b};BufferedWriter.prototype.write=function(a,b,c){var d=typeof a;if(d==="number")b=0,a=toHexArray(a),c=a.length,a=new Buffer(a);else if(d==="string")b=0,c=Buffer.byteLength(a,this._settings.encoding),a=new Buffer(a,this._settings.encoding);else{isArray(a)&&(a=new Buffer(a));var e=arguments.length;e===1&&(b=0,c=1)}return this._write(a,b,c),this},module.exports=BufferedWriter;
View
10 test/tests/node_modules/buffered-writer/package.json
@@ -1,6 +1,6 @@
{
"name": "buffered-writer",
- "version": "0.1.6",
+ "version": "0.1.7",
"description": "Fully configurable buffered writer.",
"keywords": [
"buffer",
@@ -34,13 +34,13 @@
"name": "Gagle",
"email": "gaglekas@gmail.com"
},
- "_id": "buffered-writer@0.1.6",
+ "_id": "buffered-writer@0.1.7",
"dependencies": {},
"devDependencies": {},
"optionalDependencies": {},
"_engineSupported": true,
- "_npmVersion": "1.1.19",
- "_nodeVersion": "v0.6.16",
+ "_npmVersion": "1.1.21",
+ "_nodeVersion": "v0.6.17",
"_defaultsLoaded": true,
- "_from": "buffered-writer"
+ "_from": "buffered-writer@0.1.7"
}
Please sign in to comment.
Something went wrong with that request. Please try again.