Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated modules and readme

  • Loading branch information...
commit a83be1ed58932b8bf8c39291d7b39edc70aca4b2 1 parent 98bfdb5
@gagle authored
View
2  README.md
@@ -38,5 +38,5 @@ Or simply copying `build/buffered-writer.js` into your project's directory and `
[Reference](https://github.com/Gagle/Node-BufferedWriter/wiki/Reference)
[Examples](https://github.com/Gagle/Node-BufferedWriter/tree/master/examples)
-[Change log](https://github.com/Gagle/Node-BufferedWriter/wiki/Change-log)
+[Change Log](https://github.com/Gagle/Node-BufferedWriter/wiki/Change-Log)
[MIT License](https://github.com/Gagle/Node-BufferedWriter/blob/master/LICENSE)
View
2  test/tests/node_modules/buffered-reader/README.md
@@ -7,7 +7,7 @@ Node BufferedReader
[Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
-Version: 0.2.3
+Version: 0.2.5
When you need to read a file you typically read a chunk of bytes called "buffer" to avoid multiple calls to the underlying I/O layer, so instead of reading directly from the disk, you read from the previous filled buffer. Doing this you win performance.
View
2  test/tests/node_modules/buffered-reader/buffered-reader.js
@@ -1 +1 @@
-"use strict";var EVENTS=require("events"),FS=require("fs"),BUFFER_SIZE=16384,INVALID_BUFFER_SIZE="The buffer size must be greater than 0.",INVALID_START_OFFSET="The start offset must be greater than or equals to 0.",INVALID_END_OFFSET="The end offset must be greater than or equals to 0.",INVALID_RANGE_OFFSET="The end offset must be greater than or equals to the start offset.",INVALID_BYTES_RANGE_ERROR="The number of bytes to read must be greater than 0.",INVALID_SEEK_OFFSET="The offset must be greater than or equals to 0.",NO_FILE_ERROR="The source is not a file.",BufferedReader=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,start:b.start||0,end:b.end};if(this._settings.bufferSize<1)throw new Error(INVALID_BUFFER_SIZE);if(this._settings.start<0)throw new Error(INVALID_START_OFFSET);if(this._settings.end<0)throw new Error(INVALID_END_OFFSET);if(this._settings.end<this._settings.start)throw new Error(INVALID_RANGE_OFFSET);this._fileName=a,this._fd=null,this._buffer=null,this._fileOffset=this._settings.start,this._bufferOffset=0,this._dataOffset=0,this._realOffset=this._settings.start,this._fileSize=null,this._initialized=!1,this._interrupted=!1,this._isEOF=!1,this._noMoreBuffers=!1,this._needRead=!1,this._reading=!1};BufferedReader.prototype=Object.create(EVENTS.EventEmitter.prototype),BufferedReader.prototype.constructor=BufferedReader,BufferedReader.prototype.interrupt=function(){this._reading&&(this._interrupted=!0)},BufferedReader.prototype.read=function(){this._reading=!0;var a=FS.createReadStream(this._fileName,this._settings),b=null,c=0,d=this,e=this.listeners("character").length!==0,f=this.listeners("line").length!==0,g=this.listeners("byte").length!==0,h=e||f||g;a.on("data",function(i){var j=0,k,l,m=i.length,n=!1;if(h){for(var o=0;o<m;o++){if(d._interrupted)break;l=i[o];if(!a.encoding){c++,g&&d.emit("byte",l,c);continue}c+=Buffer.byteLength(l,d._settings.encoding),e&&d.emit("character",l,c);if(!f)continue;if(l==="\r"){n=!0;continue}l==="\n"&&(k=i.slice(j,n?o-1:o),j=o+1,b&&(k=b.concat(k),b=null),d.emit("line",k,c)),n=!1}if(f&&a.encoding&&j!==m){var p=j===0?i:i.slice(j);b=b?b.concat(p):p}}d.emit("buffer",i,c),d._interrupted&&(d._interrupted=!1,a.destroy(),d.emit("end"))}),a.on("end",function(){d._interrupted=!1,h&&b&&d.emit("line",b,c),this._reading=!1,d.emit("end")}),a.on("error",function(a){d._interrupted=!1,d.emit("error",a)})},BufferedReader.prototype._init=function(a){var b=this;FS.stat(this._fileName,function(c,d){if(c)return a(c);if(d.isFile()){if(b._settings.start>=d.size)return b._isEOF=!0,a(null);!b._settings.end&&b._settings.end!==0&&(b._settings.end=d.size),b._settings.end>=d.size&&(b._settings.end=d.size-1),b._fileSize=d.size,a(null)}else a(new Error(NO_FILE_ERROR))})},BufferedReader.prototype._read=function(a){var b=this,c=this._settings.bufferSize;FS.read(this._fd,this._buffer,0,c,this._fileOffset,function(d,e){if(d)return a(d);b._fileOffset+=e,b._fileOffset===b._fileSize&&(b._noMoreBuffers=!0),e<c&&(b._buffer=b._buffer.slice(0,e)),a(null)})},BufferedReader.prototype._readBytes=function(a,b){if(this._needRead){this._needRead=!1;var c=this;this._read(function(d){if(d)return b(d,null,-1);c._readBytes(a,b)});return}var d=function(){var e=a-c._dataOffset,g=c._buffer.length-c._bufferOffset,h=g<=e?g:e;c._buffer.copy(f,c._dataOffset,c._bufferOffset,c._bufferOffset+h),c._bufferOffset+=h,c._realOffset+=h,c._bufferOffset===c._buffer.length&&(c._bufferOffset=0,c._needRead=!0),c._dataOffset+=h,c._dataOffset===a?(c._dataOffset=0,c._isEOF=c._noMoreBuffers,b(null,f,a)):c._noMoreBuffers?(c._isEOF=!0,h=c._dataOffset,c._dataOffset=0,b(null,f.slice(0,h),h)):(c._needRead=!1,c._read(function(a){if(a)return b(a,null,-1);d()}))},c=this,e=c._settings.end-c._realOffset+1;a=e<a?e:a;if(a===0)return b(null,null,0);var f=new Buffer(a),g=c._buffer.length;if(a<=g){var h=c._bufferOffset+a;if(h<=g)c._buffer.copy(f,0,c._bufferOffset,h),c._bufferOffset=h,c._realOffset+=a,b(null,f,a);else{var i=g-c._bufferOffset;c._realOffset+=i,i!==0&&c._buffer.copy(f,0,c._bufferOffset,c._bufferOffset+i);if(c._noMoreBuffers)return c._isEOF=!0,b(null,f.slice(0,i),i);c._read(function(d){if(d)return b(d,null,-1);g=c._buffer.length;var e=a-i;if(g<=e){c._realOffset+=g,c._isEOF=!0,c._buffer.copy(f,i,0,g);var h=i+g;b(null,f.slice(0,h),h)}else c._realOffset+=e,c._bufferOffset=e,c._buffer.copy(f,i,0,c._bufferOffset),b(null,f,a)})}}else d()},BufferedReader.prototype.close=function(a){a&&(a=a.bind(this));if(!this._fd){a&&a(null);return}var b=this;FS.close(this._fd,function(c){b._fd=null,b._buffer=null,a&&a(c)})},BufferedReader.prototype.readBytes=function(a,b){b=b.bind(this);if(a<1||this._isEOF)return b(null,null,0);var c=function(){if(d._isEOF)return b(null,null,0);FS.open(d._fileName,"r",function(c,e){if(c)return b(c,null,-1);d._fd=e,d._buffer=new Buffer(d._settings.bufferSize),d._read(function(c){if(c)return b(c,null,-1);d._readBytes(a,b)})})},d=this;if(!this._initialized)this._init(function(a){if(a)return b(a,null);d._initialized=!0,c()});else{if(!this._fd)return c();this._readBytes(a,b)}},BufferedReader.prototype.seek=function(a,b){b=b.bind(this);if(a<0)return b(new Error(INVALID_SEEK_OFFSET));var c=function(){a+=d._settings.start;if(a>=d._settings.end+1)d._isEOF=!0;else{d._isEOF=!1;var c=d._fileOffset-(d._buffer?d._buffer.length:0);a>=c&&a<d._fileOffset?(d._bufferOffset=a-c,d._realOffset=a):(d._needRead=d._fd?!0:!1,d._noMoreBuffers=!1,d._fileOffset=a,d._bufferOffset=0,d._realOffset=a)}b(null)},d=this;this._initialized?c():this._init(function(a){if(a)return b(a,null);d._initialized=!0,c()})},BufferedReader.prototype.skip=function(a,b){b=b.bind(this);if(a<1||this._isEOF)return b(null,0);var c=function(){var c=d._settings.end-d._realOffset+1;a=a<=c?a:c,d.seek(d._realOffset-d._settings.start+a,function(){b(null,a)})},d=this;this._initialized?c():this._init(function(a){if(a)return b(a,null);d._initialized=!0,c()})},module.exports=BufferedReader;
+"use strict";var EVENTS=require("events"),FS=require("fs"),BUFFER_SIZE=16384,INVALID_BUFFER_SIZE="The buffer size must be greater than 0.",INVALID_START_OFFSET="The start offset must be greater than or equals to 0.",INVALID_END_OFFSET="The end offset must be greater than or equals to 0.",INVALID_RANGE_OFFSET="The end offset must be greater than or equals to the start offset.",INVALID_BYTES_RANGE_ERROR="The number of bytes to read must be greater than 0.",INVALID_SEEK_OFFSET="The offset must be greater than or equals to 0.",NO_FILE_ERROR="The source is not a file.",BufferedReader=function(e,t){EVENTS.EventEmitter.call(this),t=t||{},t.bufferSize===0&&(t.bufferSize=-1),this._settings={bufferSize:t.bufferSize||BUFFER_SIZE,encoding:t.encoding||null,start:t.start||0,end:t.end};if(this._settings.bufferSize<1)throw new Error(INVALID_BUFFER_SIZE);if(this._settings.start<0)throw new Error(INVALID_START_OFFSET);if(this._settings.end<0)throw new Error(INVALID_END_OFFSET);if(this._settings.end<this._settings.start)throw new Error(INVALID_RANGE_OFFSET);this._fileName=e,this._reset()};BufferedReader.prototype=Object.create(EVENTS.EventEmitter.prototype),BufferedReader.prototype.constructor=BufferedReader,BufferedReader.prototype._init=function(e){var t=this;FS.stat(this._fileName,function(n,r){if(n)return e(n);if(r.isFile()){if(t._settings.start>=r.size)return t._isEOF=!0,e(null);!t._settings.end&&t._settings.end!==0&&(t._settings.end=r.size),t._settings.end>=r.size&&(t._settings.end=r.size-1),t._fileSize=r.size,e(null)}else e(new Error(NO_FILE_ERROR))})},BufferedReader.prototype._read=function(e){var t=this,n=this._settings.bufferSize;FS.read(this._fd,this._buffer,0,n,this._fileOffset,function(r,i){if(r)return e(r);t._fileOffset+=i,t._fileOffset===t._fileSize&&(t._noMoreBuffers=!0),i<n&&(t._buffer=t._buffer.slice(0,i)),e(null)})},BufferedReader.prototype._readBytes=function(e,t){if(this._needRead){this._needRead=!1;var n=this;this._read(function(r){if(r)return t(r,null,-1);n._readBytes(e,t)});return}var r=function(){var i=e-n._dataOffset,o=n._buffer.length-n._bufferOffset,u=o<=i?o:i;n._buffer.copy(s,n._dataOffset,n._bufferOffset,n._bufferOffset+u),n._bufferOffset+=u,n._realOffset+=u,n._bufferOffset===n._buffer.length&&(n._bufferOffset=0,n._needRead=!0),n._dataOffset+=u,n._dataOffset===e?(n._dataOffset=0,n._isEOF=n._noMoreBuffers,t(null,s,e)):n._noMoreBuffers?(n._isEOF=!0,u=n._dataOffset,n._dataOffset=0,t(null,s.slice(0,u),u)):(n._needRead=!1,n._read(function(e){if(e)return t(e,null,-1);r()}))},n=this,i=n._settings.end-n._realOffset+1;e=i<e?i:e;if(e===0)return t(null,null,0);var s=new Buffer(e),o=n._buffer.length;if(e<=o){var u=n._bufferOffset+e;if(u<=o)n._buffer.copy(s,0,n._bufferOffset,u),n._bufferOffset=u,n._realOffset+=e,t(null,s,e);else{var a=o-n._bufferOffset;n._realOffset+=a,a!==0&&n._buffer.copy(s,0,n._bufferOffset,n._bufferOffset+a);if(n._noMoreBuffers)return n._isEOF=!0,t(null,s.slice(0,a),a);n._read(function(r){if(r)return t(r,null,-1);o=n._buffer.length;var i=e-a;if(o<=i){n._realOffset+=o,n._isEOF=!0,n._buffer.copy(s,a,0,o);var u=a+o;t(null,s.slice(0,u),u)}else n._realOffset+=i,n._bufferOffset=i,n._buffer.copy(s,a,0,n._bufferOffset),t(null,s,e)})}}else r()},BufferedReader.prototype._reset=function(){this._fd=null,this._buffer=null,this._fileOffset=this._settings.start,this._bufferOffset=0,this._dataOffset=0,this._realOffset=this._settings.start,this._fileSize=null,this._initialized=!1,this._interrupted=!1,this._isEOF=!1,this._noMoreBuffers=!1,this._needRead=!1,this._reading=!1,this._stream=null},BufferedReader.prototype.close=function(e){e&&(e=e.bind(this));if(!this._fd){e&&e(null);return}var t=this;FS.close(this._fd,function(n){t._reset(),e&&e(n||null)})},BufferedReader.prototype.interrupt=function(){this._reading&&(this._interrupted=!0)},BufferedReader.prototype.pause=function(){this._stream&&this._stream.pause()},BufferedReader.prototype.read=function(){var e=this;FS.stat(this._fileName,function(t,n){if(t)return e.emit("error",t);e._reading=!0,e._stream=FS.createReadStream(e._fileName,e._settings),e._writeStream&&e._stream.pipe(e._writeStream);var r=null,i=0,s=n.size,o=e.listeners("character").length!==0,u=e.listeners("line").length!==0,a=e.listeners("byte").length!==0,f=o||u||a;e._stream.on("data",function(t){var n=0,l,c,h=t.length,p=!1;if(f){for(var d=0;d<h;d++){if(e._interrupted)break;c=t[d];if(!e._stream.encoding){i++,a&&e.emit("byte",c,i===s?-1:i);continue}i+=Buffer.byteLength(c,e._settings.encoding),o&&e.emit("character",c,i===s?-1:i);if(!u)continue;if(c==="\r"){p=!0;continue}c==="\n"&&(l=t.slice(n,p?d-1:d),n=d+1,r&&(l=r.concat(l),r=null),e.emit("line",l,i===s?-1:i)),p=!1}if(u&&e._stream.encoding&&n!==h){var v=n===0?t:t.slice(n);r=r?r.concat(v):v}}else i+=h;e.emit("buffer",t,i===s?-1:i),e._interrupted&&(e._interrupted=!1,e._stream.destroy(),e.emit("end"))}).on("end",function(){e._interrupted=!1,f&&r&&e.emit("line",r,i),e._reading=!1,e._stream=null,e.emit("end")}).on("error",function(t){e._interrupted=!1,e.emit("error",t)})})},BufferedReader.prototype.readBytes=function(e,t){t=t.bind(this);if(e<1||this._isEOF)return t(null,null,0);var n=function(){if(r._isEOF)return t(null,null,0);FS.open(r._fileName,"r",function(n,i){if(n){r.close(function(e){t(e,null,-1)});return}r._fd=i,r._buffer=new Buffer(r._settings.bufferSize),r._read(function(n){if(n){r.close(function(e){t(e,null,-1)});return}r._readBytes(e,function(e,n,i){if(e){r.close(function(e){t(e,n,i)});return}t(e,n,i)})})})},r=this;if(!this._initialized)this._init(function(e){if(e)return t(e,null);r._initialized=!0,n()});else{if(!this._fd)return n();this._readBytes(e,t)}},BufferedReader.prototype.resume=function(){this._stream&&this._stream.resume()},BufferedReader.prototype.seek=function(e,t){t=t.bind(this);if(e<0)return t(new Error(INVALID_SEEK_OFFSET));var n=function(){e+=r._settings.start;if(e>=r._settings.end+1)r._isEOF=!0;else{r._isEOF=!1;var n=r._fileOffset-(r._buffer?r._buffer.length:0);e>=n&&e<r._fileOffset?(r._bufferOffset=e-n,r._realOffset=e):(r._needRead=r._fd?!0:!1,r._noMoreBuffers=!1,r._fileOffset=e,r._bufferOffset=0,r._realOffset=e)}t(null)},r=this;this._initialized?n():this._init(function(e){if(e)return t(e,null);r._initialized=!0,n()})},BufferedReader.prototype.skip=function(e,t){t=t.bind(this);if(e<1||this._isEOF)return t(null,0);var n=function(){var n=r._settings.end-r._realOffset+1;e=e<=n?e:n,r.seek(r._realOffset-r._settings.start+e,function(){t(null,e)})},r=this;this._initialized?n():this._init(function(e){if(e)return t(e,null);r._initialized=!0,n()})},module.exports=BufferedReader;
View
6 test/tests/node_modules/buffered-reader/package.json
@@ -1,6 +1,6 @@
{
"name": "buffered-reader",
- "version": "0.2.3",
+ "version": "0.2.5",
"description": "Fully configurable buffered reader.",
"keywords": [
"buffer",
@@ -30,7 +30,7 @@
}
],
"main": "buffered-reader",
- "readme": "<a name=\"start\"></a>\r\n\r\nNode BufferedReader\r\n===================\r\n\r\n#### Fully configurable buffered reader for node.js ####\r\n\r\n[Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)\r\n\r\nVersion: 0.2.3\r\n\r\nWhen you need to read a file you typically read a chunk of bytes called \"buffer\" to avoid multiple calls to the underlying I/O layer, so instead of reading directly from the disk, you read from the previous filled buffer. Doing this you win performance.\r\n\r\nThis library allows you to read files using internal buffers, so you don't have to worry about them. In addition, you can read a text file line by line.\r\n\r\n<a name=\"availability\"></a>\r\n#### Availability [↑](#start) ####\r\n\r\nVia npm:\r\n\r\n```\r\nnpm install buffered-reader\r\n```\r\n\r\nOr simply copying `build/buffered-reader.js` into your project's directory and `require()` accordingly.\r\n\r\n***\r\n\r\n<a name=\"compatibility\"></a>\r\n#### Compatibility [↑](#start) ####\r\n\r\n✔ Node *\r\n\r\n***\r\n\r\n<a name=\"documentation\"></a>\r\n#### Documentation [↑](#start) ####\r\n \r\n[Reference](https://github.com/Gagle/Node-BufferedReader/wiki/Reference) \r\n[Examples](https://github.com/Gagle/Node-BufferedReader/tree/master/examples) \r\n[Change log](https://github.com/Gagle/Node-BufferedReader/wiki/Change-log) \r\n[MIT License](https://github.com/Gagle/Node-BufferedReader/blob/master/LICENSE)",
- "_id": "buffered-reader@0.2.3",
+ "readme": "<a name=\"start\"></a>\r\n\r\nNode BufferedReader\r\n===================\r\n\r\n#### Fully configurable buffered reader for node.js ####\r\n\r\n[Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)\r\n\r\nVersion: 0.2.5\r\n\r\nWhen you need to read a file you typically read a chunk of bytes called \"buffer\" to avoid multiple calls to the underlying I/O layer, so instead of reading directly from the disk, you read from the previous filled buffer. Doing this you win performance.\r\n\r\nThis library allows you to read files using internal buffers, so you don't have to worry about them. In addition, you can read a text file line by line.\r\n\r\n<a name=\"availability\"></a>\r\n#### Availability [↑](#start) ####\r\n\r\nVia npm:\r\n\r\n```\r\nnpm install buffered-reader\r\n```\r\n\r\nOr simply copying `build/buffered-reader.js` into your project's directory and `require()` accordingly.\r\n\r\n***\r\n\r\n<a name=\"compatibility\"></a>\r\n#### Compatibility [↑](#start) ####\r\n\r\n✔ Node *\r\n\r\n***\r\n\r\n<a name=\"documentation\"></a>\r\n#### Documentation [↑](#start) ####\r\n \r\n[Reference](https://github.com/Gagle/Node-BufferedReader/wiki/Reference) \r\n[Examples](https://github.com/Gagle/Node-BufferedReader/tree/master/examples) \r\n[Change log](https://github.com/Gagle/Node-BufferedReader/wiki/Change-log) \r\n[MIT License](https://github.com/Gagle/Node-BufferedReader/blob/master/LICENSE)",
+ "_id": "buffered-reader@0.2.5",
"_from": "buffered-reader"
}
Please sign in to comment.
Something went wrong with that request. Please try again.