Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

preparing stuff for v2.0.0

  • Loading branch information...
commit af34a270ea083b77937e39b5f462022edf441a4f 1 parent e3b1817
@gagle authored
Showing with 639 additions and 1,515 deletions.
  1. +0 −1  .gitignore
  2. +3 −4 .npmignore
  3. +4 −5 CHANGES
  4. +26 −0 README-v2.0.0.md
  5. +1 −134 README.md
  6. +184 −0 examples/id3v1.1.js
  7. BIN  examples/id3v1.1.mp3
  8. +0 −428 lib/binary-reader.js
  9. +0 −6 lib/buffered-reader.js
  10. +0 −205 lib/data-reader.js
  11. +2 −0  lib/index.js
  12. +71 −0 old/build/node_modules/errno-codes/README.md
  13. +1 −0  old/build/node_modules/errno-codes/error.js
  14. +32 −0 old/build/node_modules/errno-codes/package.json
  15. +71 −0 old/src/node_modules/errno-codes/README.md
  16. +1 −0  old/src/node_modules/errno-codes/error.js
  17. +29 −0 old/src/node_modules/errno-codes/package.json
  18. +59 −0 old/test/tests/node_modules/buffered-writer/README.md
  19. +1 −0  old/test/tests/node_modules/buffered-writer/buffered-writer.js
  20. +71 −0 old/test/tests/node_modules/buffered-writer/node_modules/errno-codes/README.md
  21. +1 −0  old/test/tests/node_modules/buffered-writer/node_modules/errno-codes/error.js
  22. +29 −0 old/test/tests/node_modules/buffered-writer/node_modules/errno-codes/package.json
  23. +42 −0 old/test/tests/node_modules/buffered-writer/package.json
  24. +11 −17 package.json
  25. +0 −255 readme_wiki.md
  26. +0 −12 tests/binary-reader/binary-reader.js
  27. +0 −438 tests/data-reader/data-reader.js
  28. +0 −10 tests/run.js
View
1  .gitignore
@@ -1 +0,0 @@
-node_modules
View
7 .npmignore
@@ -1,5 +1,4 @@
-node_modules
-tests
-.npmignore
CHANGES
-LICENSE
+examples
+test
+.npmignore
View
9 CHANGES
@@ -1,9 +1,8 @@
-v1.1.0 (xx Jan 2013)
+v2.0.0 (xx Aug 2013)
Complete code revision and refactor.
- Added Mocha tests.
- Removed backward compatibility.
- "interrupt()" renamed to "stop()".
- Reduced the number of I/O calls when the DataReader is paused and resumed.
+ The module is renamed to "binary-reader".
+ The DataReader class is removed. If you want to read lines use another module.
+ A synchronous api, but asynchronous execution, has been added.
v1.0.0 (04 Oct 2012)
Complete code refactor for better maintenance.
View
26 README-v2.0.0.md
@@ -0,0 +1,26 @@
+binary-reader
+============
+
+_Node.js project_
+
+#### Random access buffered binary reader ####
+
+Version: 0.0.1
+
+The reader allows you to position a cursor and read the bytes you need. It has an internal buffer so if the cursor is positioned inside the limits of the current buffer, the data is already into memory, so no I/O operation is required, therefore the overall performance is better.
+
+#### Installation ####
+
+```
+npm install binary-reader
+```
+
+#### Functions ####
+
+- [_module_.open(file[, options]) : undefined](#open)
+
+---
+
+<a name="open"></a>
+___module_.open(file[, options]) : undefined__
+
View
135 README.md
@@ -1,137 +1,4 @@
-# UNDER HEAVY DEVELOPMENT, THE README IS A MESS, SOMETHING WENT WRONG!
-
-
-
-<a name="start"></a>
-Node BufferedReader
-===================
-
-_Node.js project_
-
-#### Binary and event-based data buffered readers ####
-
-[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
-
-Version: 1.0.1
-
-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.
-
-This library allows you to read files without worry about the buffers. There are two ways to read the files. The first can only read binary data and has a pointer to move along the file (seek, skip, read). The second performs a read from the beginning to the end of the file and emits different events (byte, character, line, buffer...).
-
-<a name="showme"></a>
-#### Show me! [](#start) ####
-
-```javascript
-var reader = require ("buffered-reader");
-var BinaryReader = reader.BinaryReader;
-var DataReader = reader.DataReader;
-
-var close = function (binaryReader, error){
- if (error) console.log (error);
-
- binaryReader.close (function (error){
- if (error) console.log (error);
- });
-};
-
-var file = "file";
-var offset;
-
-new DataReader (file, { encoding: "utf8" })
- .on ("error", function (error){
- console.log (error);
- })
- .on ("line", function (line, nextByteOffset){
- if (line === "Phasellus ultrices ligula sed odio ultricies egestas."){
- offset = nextByteOffset;
- this.interrupt ();
- }
- })
- .on ("end", function (){
- new BinaryReader (file)
- .seek (offset, function (error){
- if (error) return close (this, error);
-
- this.read (9, function (error, bytes, bytesRead){
- if (error) return close (this, error);
-
- console.log (bytes.toString ()); //Prints: Curabitur
-
- close (this);
- });
- });
- })
- .read ();
-```
-
-file:
-
-```text
-Lorem ipsum dolor sit amet, consectetur adipiscing elit.
-Morbi convallis nibh massa, eu varius felis.
-
-Phasellus ultrices ligula sed odio ultricies egestas.
-Curabitur pretium magna in diam accumsan dignissim.
-Phasellus et tortor eu orci suscipit vehicula.
-Phasellus pulvinar mauris in purus consequat vel congue orci hendrerit.
-Pellentesque eget arcu magna, suscipit imperdiet eros.
-```
-
-***
-
-<a name="availability"></a>
-#### Availability [](#start) ####
-
-Via npm:
-
-```
-npm install buffered-reader
-```
-
-***
-
-<a name="compatibility"></a>
-#### Compatibility [](#start) ####
-
-✔ Node *
-
-***
-
-<a name="documentation"></a>
-#### Documentation [](#start) ####
-
-[Reference](https://github.com/Gagle/Node-BufferedReader/wiki/Reference)
-[Examples](https://github.com/Gagle/Node-BufferedReader/tree/master/examples)
-[Change Log](https://github.com/Gagle/Node-BufferedReader/wiki/Change-Log)
-[MIT License](https://github.com/Gagle/Node-BufferedReader/blob/master/LICENSE)
-
-
-
-
-
-
-
-
-
-
-
-
----
----
----
-
-
-
-
-
-
-
-
-
-
-
-
-
+## UNDER HEAVY DEVELOPMENT
To use the module:
View
184 examples/id3v1.1.js
@@ -0,0 +1,184 @@
+var BinaryReader = require ("../../build/buffered-reader").BinaryReader;
+
+/*
+ This example reads the ID3v1.1 tags from a mp3 file.
+
+
+
+ ID3v1/v1.1 specification
+ ------------------------
+
+ http://www.id3.org/ID3v1
+
+ The TAG is used to describe the MPEG Audio file. It contains information about
+ artist, title, album, publishing year and genre. There is some extra space for
+ comments. It is exactly 128 bytes long and is located at very end of the audio
+ data. You can get it by reading the last 128 bytes of the MPEG audio file.
+
+ AAABBBBB BBBBBBBB BBBBBBBB BBBBBBBB
+ BCCCCCCC CCCCCCCC CCCCCCCC CCCCCCCD
+ DDDDDDDD DDDDDDDD DDDDDDDD DDDDDEEE
+ EFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFG
+
+ Sign Length Position Description
+ (bytes) (bytes)
+ A 3 (0-2) Tag identification. Must contain 'TAG' if tag
+ exists and is correct.
+ B 30 (3-32) Title
+ C 30 (33-62) Artist
+ D 30 (63-92) Album
+ E 4 (93-96) Year
+ F 30 (97-126) Comment
+ G 1 (127) Genre
+
+ The specification asks for all fields to be padded with null character
+ (ASCII 0).
+
+ There is a small change proposed in ID3v1.1 structure. The last byte of the
+ Comment field may be used to specify the track number of a song in an album.
+ If the track byte is used the previous byte (28 from 0-29) must be a null character (ASCII 0).
+ It should contain a null character (ASCII 0) if the information is unknown.
+
+ Genre list:
+
+ 0 - Blues
+ 1 - Classic Rock
+ 2 - Country
+ 3 - Dance
+ ...
+ 137 - Heavy Metal
+ ...
+
+
+ The content of the file is:
+
+ Offset 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+
+ 0230 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. <music data>
+ 0240 54 41 47 42 72 65 61 6B 69 6E 67 20 54 68 65 20 TAGBreaking The
+ 0250 4C 61 77 00 00 00 00 00 00 00 00 00 00 00 00 00 Law.............
+ 0260 00 4A 75 64 61 73 20 50 72 69 65 73 74 00 00 00 .Judas Priest...
+ 0270 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 ...............B
+ 0280 72 69 74 69 73 68 20 53 74 65 65 6C 00 00 00 00 ritish Steel....
+ 0290 00 00 00 00 00 00 00 00 00 00 00 00 00 31 39 38 .............198
+ 02A0 30 47 72 65 61 74 20 73 6F 6E 67 21 00 00 00 00 0Great song!....
+ 02B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 33 89 ..............3‰
+*/
+
+//ID3v1.1 tags
+var tags = {
+ title: null,
+ artist: null,
+ album: null,
+ year: null,
+ comment: null,
+ track: null,
+ genre: null
+};
+
+var genres = {
+ "0": "Blues",
+ "1": "Classic Rock",
+ "2": "Country",
+ "3": "Dance",
+ "137": "Heavy Metal"
+};
+
+var close = function (binaryReader, error){
+ if (error) console.log (error);
+
+ binaryReader.close (function (error){
+ if (error) console.log (error);
+ });
+};
+
+var printTags = function (){
+ console.log ("Title:\t\t" + tags.title);
+ console.log ("Artist:\t\t" + tags.artist);
+ console.log ("Album:\t\t" + tags.album);
+ console.log ("Year:\t\t" + tags.year);
+ console.log ("Comment:\t" + tags.comment);
+ console.log ("Track:\t\t" + tags.track);
+ console.log ("Genre:\t\t" + genres[tags.genre]);
+};
+
+//Default buffer if not specified is 16KB. Try changing this value, the result should be the same.
+var bufferSize = 16384;
+
+//The window starts from byte 127 starting from the end of the file, in our case the byte at the
+//offset 0240, value 54. The end limit is automatically set, it's the file size minus 1, offset
+//02BF, value 89
+new BinaryReader ("id3v1.1.mp3", { bufferSize: bufferSize, start: 127, fromEnd: true })
+ //The text has ASCII encoding so it's safe to read 1 byte per chararacter
+ //Check if TAG is present, if so the music file has ID3v1/v1.1 tags
+ .read (3, function (error, bytes, bytesRead){
+ if (error) return close (this, error);
+
+ if (bytes.toString ("ascii") !== "TAG"){
+ console.log ("The music file doesn't have ID3v1/v1.1 tags.");
+ close (this);
+ return;
+ }
+
+ //Read title
+ this.read (30, function (error, bytes, bytesRead){
+ if (error) return close (this, error);
+
+ tags.title = bytes.toString ("ascii");
+
+ //Read artist
+ this.read (30, function (error, bytes, bytesRead){
+ if (error) return close (this, error);
+
+ tags.artist = bytes.toString ("ascii");
+
+ //Read album
+ this.read (30, function (error, bytes, bytesRead){
+ if (error) return close (this, error);
+
+ tags.album = bytes.toString ("ascii");
+
+ //Read year
+ this.read (4, function (error, bytes, bytesRead){
+ if (error) return close (this, error);
+
+ tags.year = bytes.toString ("ascii");
+
+ //Read comment
+ this.read (29, function (error, bytes, bytesRead){
+ if (error) return close (this, error);
+
+ tags.comment = bytes.toString ("ascii");
+ var isLastCharNullByte = bytes[28] === 0x00;
+
+ //Read track
+ this.read (1, function (error, bytes, bytesRead){
+ if (error) return close (this, error);
+
+ if (isLastCharNullByte){
+ tags.track = bytes.toString ("ascii");
+ }else{
+ tags.comment += bytes.toString ("ascii");
+ }
+
+ //Read genre
+ this.read (1, function (error, bytes, bytesRead){
+ if (error) return close (this, error);
+
+ tags.genre = bytes[0];
+
+ //We should have reached the end of the window/file
+ if (this.isOffsetOutOfWindow ()){
+ console.log ("All tags has been read successfully!\n");
+ printTags ();
+ }
+
+ close (this);
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+ });
View
BIN  examples/id3v1.1.mp3
Binary file not shown
View
428 lib/binary-reader.js
@@ -1,428 +0,0 @@
-"use strict";
-
-
-/*Error.create (Error.getNextAvailableErrno (), "INVALID_WINDOW_START_OFFSET",
- "The start offset must be greater than or equals to 0.");
-Error.create (Error.getNextAvailableErrno (), "INVALID_WINDOW_END_OFFSET",
- "The end offset must be greater than or equals to 0.");
-Error.create (Error.getNextAvailableErrno (), "INVALID_WINDOW_RANGE_OFFSET",
- "The end offset must be greater than or equals to the start offset and both of them must" +
- " be inside the file range. Window: [{ws}, {we}], File: [0, {fe}].");
-Error.create (Error.getNextAvailableErrno (), "INVALID_SEEK_OFFSET",
- "The relative offset must be inside the window range. Relative offset: {offset}, Relative" +
- " window: [0, {we}].");
-Error.create (Error.getNextAvailableErrno (), "NO_FILE",
- "The source is not a file.");
-Error.create (Error.getNextAvailableErrno (), "EMPTY_FILE",
- "The file is empty.");
-Error.create (Error.getNextAvailableErrno (), "INVALID_READ_BYTES",
- "The number of bytes to read must be equal or greater than 1.");
-*/
-
-var br = module.exports = {};
-
-br.open = function (file, args){
- return new BinaryReader (file, args);
-};
-
-
-
-
-var File = function (name){
- this._name = name;
- this._fd = null;
- this.size = null;
- this.isFile = null;
-};
-
-File.prototype.readMetadata = function (cb){
- var me = this;
- FS.stat (this._name, function (error, stats){
- if (error) return cb (error);
- if (stats.size === 0) return cb (Error.get (Error.EMPTY_FILE));
- me.size = stats.size;
- me.isFile = stats.isFile ();
- cb (null);
- });
-};
-
-File.prototype.close = function (cb){
- if (this._fd === null) return cb (null);
-
- FS.close (this._fd, function (error){
- cb (error || null);
- });
-};
-
-File.prototype.open = function (cb){
- if (this._fd !== null) return cb (null, this._fd);
-
- var me = this;
- FS.open (this._name, "r", function (error, fd){
- if (error) return cb (error, null);
-
- me._fd = fd;
- cb (null, fd);
- });
-};
-
-var Frame = function (br, size){
- if (size < 1){
- throw Error.get (Error.INVALID_BUFFER_SIZE);
- }else if (size === undefined || size === null){
- size = Frame.DEFAULT_SIZE;
- }
-
- this._bufferedReader = br;
- this._buffer = null;
- this._size = size;
-
- //Offsets que marcan el rango de bytes validos que se encuentra en el frame
- this._fileStart = null;
- this._fileEnd = null;
-};
-
-Frame.DEFAULT_SIZE = 16384;
-
-Frame.prototype.toFrameOffset = function (offset){
- return offset - this._fileStart;
-};
-
-Frame.prototype.isInside = function (offset){
- return this._buffer === null ? false : offset >= this._fileStart && offset <= this._fileEnd;
-};
-
-Frame.prototype.isLastFrame = function (){
- return this._buffer === null ? false : this._fileEnd === this._bufferedReader._window._end;
-};
-
-Frame.prototype.length = function (){
- return this._fileEnd - this._fileStart + 1;
-};
-
-Frame.prototype.read = function (cb){
- if (this._buffer === null){
- this._buffer = new Buffer (this._size);
- }
-
- var me = this;
-
- this._bufferedReader._file.open (function (error, fd){
- if (error) return cb (error);
-
- var length = me._bufferedReader._window._end - me._bufferedReader._globalOffset + 1;
- if (length > me._size){
- length = me._size;
- }
-
- FS.read (fd, me._buffer, 0, length, me._bufferedReader._globalOffset,
- function (error, bytesRead){
- if (error) return cb (error);
-
- me._fileStart = me._bufferedReader._globalOffset;
- me._fileEnd = me._fileStart + bytesRead - 1;
-
- cb (null);
- });
- });
-};
-
-var Window = function (start, end, fromEnd){
- if (!fromEnd){
- if (start === undefined || start === null){
- start = 0;
- }
-
- if (start < 0) throw Error.get (Error.INVALID_WINDOW_START_OFFSET);
- if (end < 0) throw Error.get (Error.INVALID_WINDOW_END_OFFSET);
- if ((start > end) && end !== undefined && end !== null){
- throw Error.get (Error.INVALID_WINDOW_RANGE_OFFSET,
- { ws: start, we: end, fe: undefined });
- }
- }else{
- if ((end > start) && end !== undefined && end !== null &&
- start !== undefined && start !== null){
- throw Error.get (Error.INVALID_WINDOW_RANGE_OFFSET,
- { ws: start, we: end, fe: undefined });
- }
- }
-
- this._fromEnd = fromEnd;
- this._start = start;
- this._end = end;
-};
-
-Window.prototype.toAbsoluteOffset = function (relativeOffset){
- if (relativeOffset === BinaryReader.START_OF_WINDOW){
- return this._start;
- }else if (relativeOffset === BinaryReader.END_OF_WINDOW){
- return this._end;
- }
- return this._start + relativeOffset;
-};
-
-Window.prototype.isInside = function (relativeOffset){
- if (relativeOffset === BinaryReader.START_OF_WINDOW ||
- relativeOffset === BinaryReader.END_OF_WINDOW){
- return true;
- }
- return relativeOffset >= 0 && relativeOffset <= this._end - this._start;
-};
-
-Window.prototype.setEnd = function (end){
- if (this._fromEnd){
- this._start = this._start !== undefined && this._start !== null ? end - this._start : end;
- this._end = this._end !== undefined && this._end !== null ? end - this._end : end;
-
- if (this._start > this._end){
- return Error.get (Error.INVALID_WINDOW_RANGE_OFFSET,
- { ws: this._start, we: this._end, fe: end });
- }
- }else{
- if (this._end === undefined || this._end === null){
- if (this._start > end){
- return Error.get (Error.INVALID_WINDOW_RANGE_OFFSET,
- { ws: this._start, we: this._end, fe: end });
- }
-
- this._end = end;
- }
- }
-
- return null;
-};
-
-
-
-var BinaryReader = function (fileName, settings){
- settings = settings || {};
-
- if (settings.bufferSize === 0) settings.bufferSize = -1;
-
- this._window = new Window (settings.start, settings.end, settings.fromEnd);
- this._file = new File (fileName);
- this._frame = new Frame (this, settings.bufferSize);
- this._initialized = false;
-
- //Offset que apunta a un byte de la totalidad del archivo y que marca desde donde hacer la
- //proxima lectura
- this._globalOffset = null;
-};
-
-BinaryReader.START_OF_WINDOW = {};
-BinaryReader.END_OF_WINDOW = {};
-
-BinaryReader.prototype._init = function (cb){
- if (!this._initialized){
- var me = this;
-
- this._file.readMetadata (function (error){
- if (error) return cb (error);
-
- if (me._file.isFile){
- var error = null;
-
- //Si no hay limite final de ventana, dicho limite pasa a ser el final del archivo
- error = me._window.setEnd (me._file.size - 1);
- me._globalOffset = me._window._start;
- if (!error) me._initialized = true;
- cb (error);
- }else{
- cb (Error.get (Error.NO_FILE));
- }
- });
- }else{
- cb (null);
- }
-};
-
-BinaryReader.prototype.close = function (cb){
- cb = cb.bind (this);
- this._file.close (function (error){
- cb (error || null);
- });
-};
-
-BinaryReader.prototype.getOffset = function (){
- return this._globalOffset;
-};
-
-BinaryReader.prototype.isOffsetOutOfWindow = function (){
- return this._globalOffset === -1;
-};
-
-BinaryReader.prototype.read = function (bytes, cb){
- cb = cb.bind (this);
- if (bytes < 1) return cb (Error.get (Error.INVALID_READ_BYTES), null, 0);
- if (this.isOffsetOutOfWindow ()) return cb (null, new Buffer (0), 0);
-
- //Corrijo la cantidad de bytes a leer segun el tamaño de la ventana
- var remainingFileBytes = this._window._end - this._globalOffset + 1;
- if (bytes > remainingFileBytes) bytes = remainingFileBytes;
- var targetBuffer = new Buffer (bytes);
-
- var me = this;
-
- var copy = function (){
- //Copio el contenido del frame al buffer de retorno
- var targetStart = 0;
- var bytesToRead = bytes;
- var sourceEnd = me._globalOffset + bytes - 1;
- var secondRead = false;
-
- if (sourceEnd > me._frame._fileEnd){
- secondRead = true;
- sourceEnd = me._frame._fileEnd;
- }
-
- //Copio la primera o unica parte
- me._frame._buffer.copy (targetBuffer, targetStart,
- me._frame.toFrameOffset (me._globalOffset),
- me._frame.toFrameOffset (sourceEnd + 1));
-
- var bytesWritten = sourceEnd - me._globalOffset + 1;
- bytesToRead -= bytesWritten;
- targetStart += bytesWritten;
-
- if (secondRead){
- me._globalOffset += bytesWritten;
-
- me._frame.read (function (error){
- if (error) return cb (error, null, null);
-
- me._frame._buffer.copy (targetBuffer, targetStart, 0, bytesToRead);
- me._globalOffset += bytesToRead;
- if (me._globalOffset === me._window._end + 1){
- me._globalOffset = -1;
- }
-
- cb (null, targetBuffer, bytes);
- });
- }else{
- me._globalOffset += bytes;
- if (me._globalOffset === me._window._end + 1){
- me._globalOffset = -1;
- }
-
- cb (null, targetBuffer, bytes);
- }
- };
-
- var fill = function (remainingBytes, targetStart){
- if (me._globalOffset > me._frame._fileEnd){
- me._frame.read (function (error){
- if (error) return cb (error, null, 0);
- fill (remainingBytes, targetStart);
- });
- return;
- }
-
- //Cada vez que se llama a esta funcion hay que preguntarse: cuantos bytes hay que leer
- //del frame actual?
- var bytesToRead = me._frame._fileEnd - me._globalOffset + 1;
- if (bytesToRead > remainingBytes){
- bytesToRead = remainingBytes;
- }
-
- var relativeOffset = me._frame.toFrameOffset (me._globalOffset);
-
- me._frame._buffer.copy (targetBuffer, targetStart, relativeOffset,
- relativeOffset + bytesToRead);
-
- me._globalOffset += bytesToRead;
- targetStart += bytesToRead;
- remainingBytes -= bytesToRead;
-
- if (remainingBytes === 0) return cb (null, targetBuffer, bytes);
- fill (remainingBytes, targetStart);
- };
-
- var read = function (){
- /*
- Si los bytes que se quieren leer superan el limite de la ventana automaticamente se
- se acortan al limite de esta, por tanto, en los siguientes casos el numero de bytes
- siempre sera un valor valido dentro de la ventana.
-
- Hay 2 casos:
-
- (1) La cantidad de bytes a leer es menor o igual que el tamaño del frame.
- Es posible que se tenga que volver a hacer otra lectura porque los bytes a leer
- pueden estar entre 2 lecturas de frame.
-
- Frame de 4 bytes: b0.b1.b2.b3
- Offset global: b2
- Bytes que se quieren leer: 4
- Bytes que se tienen que leer: b2.b3, lectura, b4.b5
-
- (2) La cantidad de bytes a leer es mayor que el tamaño del frame.
- Hay que ir haciendo lecturas e ir guardandolas en el buffer de retorno hasta que
- este se llene o se llegue al final de la ventana.
-
- Frame de 4 bytes: b0.b1.b2.b3
- Offset global: b2
- Bytes que se quieren leer: 10
- Bytes que se tienen que leer: b2.b3, lectura, b4.b5.b6.b7, lectura, b8.b9.b10.11
- */
-
- if (bytes <= me._frame.length ()){
- //Caso 1
- copy ();
- }else{
- //Caso 2
- fill (bytes, 0);
- }
- };
-
- this._init (function (error){
- if (error) return cb (error);
-
- if (!me._frame.isInside (me._globalOffset)){
- me._frame.read (function (error){
- if (error) return cb (error, null, 0);
- read ();
- });
- }else{
- read ();
- }
- });
-};
-
-BinaryReader.prototype.seek = function (offset, cb){
- cb = cb.bind (this);
- var me = this;
-
- this._init (function (error){
- if (error) return cb (error);
-
- if (me._window.isInside (offset)){
- me._globalOffset = me._window.toAbsoluteOffset (offset);
- cb (null);
- }else{
- cb (Error.get (Error.INVALID_SEEK_OFFSET,
- { offset: offset, we: me._window._end - me._window._start }));
- }
- });
-};
-
-BinaryReader.prototype.skip = function (bytes, cb){
- cb = cb.bind (this);
- var me = this;
-
- if (bytes === 0 || this.isOffsetOutOfWindow ()) return cb (null, 0);
-
- this._init (function (error){
- if (error) return cb (error, null);
-
- var offset = me._globalOffset + bytes;
- if (offset > me._window._end){
- offset = me._window._end;
- bytes = me._window._end - me._globalOffset;
- }else if (offset < me._window._start){
- offset = me._window._start;
- bytes = me._window._start - me._globalOffset;
- }
- me._globalOffset = offset;
-
- cb (null, bytes);
- });
-};
View
6 lib/buffered-reader.js
@@ -1,6 +0,0 @@
-"use strict";
-
-module.exports = {
- DataReader: require ("./data-reader"),
- BinaryReader: require ("./binary-reader"),
-};
View
205 lib/data-reader.js
@@ -1,205 +0,0 @@
-"use strict";
-
-var events = require ("events");
-var fs = require ("fs");
-var ep = require ("error-provider");
-
-ep.create (ep.next (), "INVALID_BUFFER_SIZE",
- "The buffer size must be greater than 0");
-ep.create (ep.next (), "BINARY_DATA",
- "Cannot configure a character or line listeners when the file is opened " +
- "without an encoding (read as binary data)");
-
-var WIN = process.platform === "win32";
-var BUFFER_SIZE = 16384;
-
-var dr = module.exports = {};
-
-dr.open = function (file, args){
- args = args || {};
-
- if (args.bufferSize === 0) args.bufferSize = -1;
- args.bufferSize = args.bufferSize || BUFFER_SIZE;
- if (args.bufferSize < 1) throw ep.get ("INVALID_BUFFER_SIZE");
-
- return new Reader (file, args);
-};
-
-var Reader = function (file, args){
- events.EventEmitter.call (this);
-
- this._bufferSize = args.bufferSize;
- this._encoding = args.encoding;
- this._file = file;
- this._reset ();
-};
-
-Reader.prototype = Object.create (events.EventEmitter.prototype);
-Reader.prototype.constructor = Reader;
-
-Reader.prototype._reset = function (){
- this._reading = false;
- this._paused = false;
- this._start = 0;
- //Last line not terminated with an EOL
- this._line = "";
- this._stream = null;
- //Previous loaded buffer
- this._buffer = null;
- //Previous index before pause
- this._index = 0;
-};
-
-Reader.prototype.stop = function (){
- if (!this._reading) return;
- this._stream.destroy ();
- this._reset ();
- this.emit ("end");
-};
-
-Reader.prototype.pause = function (){
- if (this._paused) return;
- this._paused = true;
- this._stream.destroy ();
-};
-
-Reader.prototype._emit = function (size){
- var me = this;
-
- var nextByteOffset = function (){
- return me._start === size ? -1 : me._start;
- };
-
- //Paused at the end of the file just before the end event
- if (this._start === size){
- this.emit ("end");
- return true;
- }
- //Paused after a buffer event, there's no more data to emit
- if (!this._buffer) return false;
-
- var len = this._buffer.length;
- var c;
- var isCR = false;
- var line;
- var lineOffset = 0;
-
- if (this._loop){
- for (var i=this._index; i<len; i++, this._index++){
- //Paused or stopped from a byte, character or line event
- if (!this._reading || this._paused) return false;
-
- c = this._buffer[i];
-
- if (!this._encoding){
- this._start++;
- this.emit ("byte", c, nextByteOffset ());
- continue;
- }
-
- this._start += Buffer.byteLength (c, this._encoding);
- this.emit ("character", c, nextByteOffset ());
-
- if (!this._listeners.onLine) continue;
-
- if (!WIN && c === "\r"){
- isCR = true;
- continue;
- }
-
- if (c === "\n"){
- line = this._buffer.substring (lineOffset, isCR ? i - 1 : i);
- lineOffset = i + 1;
-
- if (this._line){
- line = this._line + line;
- this._line = "";
- }
-
- this.emit ("line", line, nextByteOffset ());
- }
-
- isCR = false;
- }
-
- this._index = 0;
-
- if (this._listeners.onLine){
- this._line += this._buffer.substring (lineOffset);
- }
- }else{
- this._start += len;
- }
-
- var buffer = this._buffer;
- this._buffer = null;
- this.emit ("buffer", buffer, nextByteOffset ());
-
- return false;
-};
-
-Reader.prototype._readListeners = function (){
- if (this._listeners) return;
- this._listeners = {
- onByte: this.listeners ("byte").length !== 0,
- onChar: this.listeners ("character").length !== 0,
- onLine: this.listeners ("line").length !== 0,
- };
- this._loop = this._listeners.onChar || this._listeners.onLine ||
- this._listeners.onByte;
-};
-
-Reader.prototype.read = function (){
- if (this._reading && this._paused) return;
- this._reading = true;
- var me = this;
-
- this._readListeners ();
-
- if (!this._encoding && (this._listeners.onChar || this._listeners.onLine)){
- this.emit ("error", ep.get ("BINARY_DATA"));
- return;
- }
-
- fs.stat (this._file, function (error, stats){
- if (error) return me.emit ("error", error);
-
- var size = stats.size;
-
- if (size === 0) return me.emit ("end");
-
- //If the reader is paused the previous buffer contains valid data that
- //should be emitted
- //If all the file has been read the stream does not need to be re-created
- if (me._emit (size)) return;
-
- me._stream = fs.createReadStream (me._file, {
- bufferSize: me._bufferSize,
- encoding: me._encoding,
- start: me._start
- });
-
- me._stream
- .on ("error", function (error){
- me._stream.destroy ();
- me.emit ("error", error);
- })
- .on ("end", function (){
- if (me._line){
- me.emit ("line", me._line, -1);
- }
- me._reset ();
- me.emit ("end");
- })
- .on ("data", function (buffer){
- me._buffer = buffer;
- me._emit ();
- });
- });
-};
-
-Reader.prototype.resume = function (){
- if (!this._paused) return;
- this._paused = false;
- this.read ();
-};
View
2  lib/index.js
@@ -0,0 +1,2 @@
+"use strict";
+
View
71 old/build/node_modules/errno-codes/README.md
@@ -0,0 +1,71 @@
+<a name="start"></a>
+
+Node Error
+==========
+
+_Node.js project_
+
+#### Exposes the errno codes ####
+
+[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
+
+Version: 1.0.2
+
+When you are writing a node.js module you"ll probably deal with errors. If you get a predefined error you can just throw it via a callback but if you want to instantiate a predefined one you need an errno code. Node.js does not expose these errors. Furthermore, they"re not the standard errno codes. They are defined at [`deps/uv/include/uv.h`](https://github.com/joyent/node/blob/master/deps/uv/include/uv.h).
+
+This module eases the error management providing predefined `Error` instances for every errno code and the ability to create customized errors.
+
+<a name="showme"></a>
+#### Show me! [](#start) ####
+
+```javascript
+var Error = require ("errno-codes");
+
+console.log (Error.get (Error.ENOENT));
+
+var errno = Error.getNextAvailableErrno ();
+Error.create (errno, "TEST1", "test 1");
+console.log (Error.get (Error.TEST1));
+console.log (Error.get ("TEST1"));
+console.log (Error.get (errno));
+
+/*
+Prints:
+
+{ [Error: ENOENT]
+ errno: 34,
+ code: "ENOENT",
+ description: "no such file or directory" }
+{ [Error: TEST1] errno: 100, code: "TEST1", description: "test 1" }
+{ [Error: TEST1] errno: 100, code: "TEST1", description: "test 1" }
+{ [Error: TEST1] errno: 100, code: "TEST1", description: "test 1" }
+*/
+```
+
+***
+
+<a name="availability"></a>
+#### Availability [](#start) ####
+
+Via npm:
+
+```
+npm install errno-codes
+```
+
+***
+
+<a name="compatibility"></a>
+#### Compatibility [](#start) ####
+
+✔ Node *
+
+***
+
+<a name="documentation"></a>
+#### Documentation [](#start) ####
+
+[Reference](https://github.com/Gagle/Node-Error/wiki/Reference)
+[Examples](https://github.com/Gagle/Node-Error/tree/master/examples)
+[Change Log](https://github.com/Gagle/Node-Error/wiki/Change-Log)
+[MIT License](https://github.com/Gagle/Node-Error/blob/master/LICENSE)
View
1  old/build/node_modules/errno-codes/error.js
@@ -0,0 +1 @@
+"use strict";var errors={UNKNOWN:{errno:-1,code:"UNKNOWN",description:"unknown error"},OK:{errno:0,code:"OK",description:"success"},EOF:{errno:1,code:"EOF",description:"end of file"},EADDRINFO:{errno:2,code:"EADDRINFO",description:"getaddrinfo error"},EACCES:{errno:3,code:"EACCES",description:"permission denied"},EAGAIN:{errno:4,code:"EAGAIN",description:"no more processes"},EADDRINUSE:{errno:5,code:"EADDRINUSE",description:"address already in use"},EADDRNOTAVAIL:{errno:6,code:"EADDRNOTAVAIL",description:""},EAFNOSUPPORT:{errno:7,code:"EAFNOSUPPORT",description:""},EALREADY:{errno:8,code:"EALREADY",description:""},EBADF:{errno:9,code:"EBADF",description:"bad file descriptor"},EBUSY:{errno:10,code:"EBUSY",description:"resource busy or locked"},ECONNABORTED:{errno:11,code:"ECONNABORTED",description:"software caused connection abort"},ECONNREFUSED:{errno:12,code:"ECONNREFUSED",description:"connection refused"},ECONNRESET:{errno:13,code:"ECONNRESET",description:"connection reset by peer"},EDESTADDRREQ:{errno:14,code:"EDESTADDRREQ",description:"destination address required"},EFAULT:{errno:15,code:"EFAULT",description:"bad address in system call argument"},EHOSTUNREACH:{errno:16,code:"EHOSTUNREACH",description:"host is unreachable"},EINTR:{errno:17,code:"EINTR",description:"interrupted system call"},EINVAL:{errno:18,code:"EINVAL",description:"invalid argument"},EISCONN:{errno:19,code:"EISCONN",description:"socket is already connected"},EMFILE:{errno:20,code:"EMFILE",description:"too many open files"},EMSGSIZE:{errno:21,code:"EMSGSIZE",description:"message too long"},ENETDOWN:{errno:22,code:"ENETDOWN",description:"network is down"},ENETUNREACH:{errno:23,code:"ENETUNREACH",description:"network is unreachable"},ENFILE:{errno:24,code:"ENFILE",description:"file table overflow"},ENOBUFS:{errno:25,code:"ENOBUFS",description:"no buffer space available"},ENOMEM:{errno:26,code:"ENOMEM",description:"not enough memory"},ENOTDIR:{errno:27,code:"ENOTDIR",description:"not a directory"},EISDIR:{errno:28,code:"EISDIR",description:"illegal operation on a directory"},ENONET:{errno:29,code:"ENONET",description:"machine is not on the network"},ENOTCONN:{errno:31,code:"ENOTCONN",description:"socket is not connected"},ENOTSOCK:{errno:32,code:"ENOTSOCK",description:"socket operation on non-socket"},ENOTSUP:{errno:33,code:"ENOTSUP",description:"operation not supported on socket"},ENOENT:{errno:34,code:"ENOENT",description:"no such file or directory"},ENOSYS:{errno:35,code:"ENOSYS",description:"function not implemented"},EPIPE:{errno:36,code:"EPIPE",description:"broken pipe"},EPROTO:{errno:37,code:"EPROTO",description:"protocol error"},EPROTONOSUPPORT:{errno:38,code:"EPROTONOSUPPORT",description:"protocol not supported"},EPROTOTYPE:{errno:39,code:"EPROTOTYPE",description:"protocol wrong type for socket"},ETIMEDOUT:{errno:40,code:"ETIMEDOUT",description:"connection timed out"},ECHARSET:{errno:41,code:"ECHARSET",description:""},EAIFAMNOSUPPORT:{errno:42,code:"EAIFAMNOSUPPORT",description:""},EAISERVICE:{errno:44,code:"EAISERVICE",description:""},EAISOCKTYPE:{errno:45,code:"EAISOCKTYPE",description:""},ESHUTDOWN:{errno:46,code:"ESHUTDOWN",description:""},EEXIST:{errno:47,code:"EEXIST",description:"file already exists"},ESRCH:{errno:48,code:"ESRCH",description:"no such process"},ENAMETOOLONG:{errno:49,code:"ENAMETOOLONG",description:"name too long"},EPERM:{errno:50,code:"EPERM",description:"operation not permitted"},ELOOP:{errno:51,code:"ELOOP",description:"too many symbolic links encountered"},EXDEV:{errno:52,code:"EXDEV",description:"cross-device link not permitted"},ENOTEMPTY:{errno:53,code:"ENOTEMPTY",description:"directory not empty"},ENOSPC:{errno:54,code:"ENOSPC",description:"no space left on device"},EIO:{errno:55,code:"EIO",description:"i/o error"},EROFS:{errno:56,code:"EROFS",description:"read-only file system"},ENODEV:{errno:57,code:"ENODEV",description:"no such device"},ESPIPE:{errno:58,code:"ESPIPE",description:"invalid seek"},ECANCELED:{errno:59,code:"ECANCELED",description:"operation canceled"}},codes={"-1":"UNKNOWN",0:"OK",1:"EOF",2:"EADDRINFO",3:"EACCES",4:"EAGAIN",5:"EADDRINUSE",6:"EADDRNOTAVAIL",7:"EAFNOSUPPORT",8:"EALREADY",9:"EBADF",10:"EBUSY",11:"ECONNABORTED",12:"ECONNREFUSED",13:"ECONNRESET",14:"EDESTADDRREQ",15:"EFAULT",16:"EHOSTUNREACH",17:"EINTR",18:"EINVAL",19:"EISCONN",20:"EMFILE",21:"EMSGSIZE",22:"ENETDOWN",23:"ENETUNREACH",24:"ENFILE",25:"ENOBUFS",26:"ENOMEM",27:"ENOTDIR",28:"EISDIR",29:"ENONET",31:"ENOTCONN",32:"ENOTSOCK",33:"ENOTSUP",34:"ENOENT",35:"ENOSYS",36:"EPIPE",37:"EPROTO",38:"EPROTONOSUPPORT",39:"EPROTOTYPE",40:"ETIMEDOUT",41:"ECHARSET",42:"EAIFAMNOSUPPORT",44:"EAISERVICE",45:"EAISOCKTYPE",46:"ESHUTDOWN",47:"EEXIST",48:"ESRCH",49:"ENAMETOOLONG",50:"EPERM",51:"ELOOP",52:"EXDEV",53:"ENOTEMPTY",54:"ENOSPC",55:"EIO",56:"EROFS",57:"ENODEV",58:"ESPIPE",59:"ECANCELED"},nextAvailableErrno=100;errors.create=function(a,b,c){var d={errno:a,code:b,description:c};errors[b]=d,codes[a]=b},errors.get=function(a,b){var c,d=typeof a;d==="number"?c=errors[codes[a]]:d==="string"?c=errors[a]:c=a;var e=new Error(c.code);e.errno=c.errno,e.code=c.code;var f=c.description;if(b)for(var g in b)f=f.replace(new RegExp("\\{"+g+"\\}","g"),b[g]);return e.description=f,e},errors.getNextAvailableErrno=function(){var a=nextAvailableErrno;return nextAvailableErrno++,a},module.exports=errors;
View
32 old/build/node_modules/errno-codes/package.json
@@ -0,0 +1,32 @@
+{
+ "name": "errno-codes",
+ "version": "1.0.2",
+ "description": "Exposes the errno codes.",
+ "keywords": [
+ "error",
+ "errno"
+ ],
+ "author": {
+ "name": "Gabriel Llamas"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Gagle/Node-Error.git"
+ },
+ "engines": {
+ "node": "*"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://www.opensource.org/licenses/mit-license.html"
+ }
+ ],
+ "main": "error",
+ "readme": "<a name=\"start\"></a>\r\n\r\nNode Error\r\n==========\r\n\r\n_Node.js project_\r\n\r\n#### Exposes the errno codes ####\r\n\r\n[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)\r\n\r\nVersion: 1.0.2\r\n\r\nWhen you are writing a node.js module you\"ll probably deal with errors. If you get a predefined error you can just throw it via a callback but if you want to instantiate a predefined one you need an errno code. Node.js does not expose these errors. Furthermore, they\"re not the standard errno codes. They are defined at [`deps/uv/include/uv.h`](https://github.com/joyent/node/blob/master/deps/uv/include/uv.h).\r\n\r\nThis module eases the error management providing predefined `Error` instances for every errno code and the ability to create customized errors.\r\n\r\n<a name=\"showme\"></a>\r\n#### Show me! [↑](#start) ####\r\n\r\n```javascript\r\nvar Error = require (\"errno-codes\");\r\n\r\nconsole.log (Error.get (Error.ENOENT));\r\n\r\nvar errno = Error.getNextAvailableErrno ();\r\nError.create (errno, \"TEST1\", \"test 1\");\r\nconsole.log (Error.get (Error.TEST1));\r\nconsole.log (Error.get (\"TEST1\"));\r\nconsole.log (Error.get (errno));\r\n\r\n/*\r\nPrints:\r\n\r\n{ [Error: ENOENT]\r\n errno: 34,\r\n code: \"ENOENT\",\r\n description: \"no such file or directory\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n*/\r\n```\r\n\r\n***\r\n\r\n<a name=\"availability\"></a>\r\n#### Availability [↑](#start) ####\r\n\r\nVia npm:\r\n\r\n```\r\nnpm install errno-codes\r\n```\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-Error/wiki/Reference) \r\n[Examples](https://github.com/Gagle/Node-Error/tree/master/examples) \r\n[Change Log](https://github.com/Gagle/Node-Error/wiki/Change-Log) \r\n[MIT License](https://github.com/Gagle/Node-Error/blob/master/LICENSE)",
+ "_id": "errno-codes@1.0.2",
+ "dist": {
+ "shasum": "b8be551b5f5680bd6f5ec43bed8f9db29e8cf034"
+ },
+ "_from": "errno-codes@1.0.2"
+}
View
71 old/src/node_modules/errno-codes/README.md
@@ -0,0 +1,71 @@
+<a name="start"></a>
+
+Node Error
+==========
+
+_Node.js project_
+
+#### Exposes the errno codes ####
+
+[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
+
+Version: 1.0.2
+
+When you are writing a node.js module you"ll probably deal with errors. If you get a predefined error you can just throw it via a callback but if you want to instantiate a predefined one you need an errno code. Node.js does not expose these errors. Furthermore, they"re not the standard errno codes. They are defined at [`deps/uv/include/uv.h`](https://github.com/joyent/node/blob/master/deps/uv/include/uv.h).
+
+This module eases the error management providing predefined `Error` instances for every errno code and the ability to create customized errors.
+
+<a name="showme"></a>
+#### Show me! [](#start) ####
+
+```javascript
+var Error = require ("errno-codes");
+
+console.log (Error.get (Error.ENOENT));
+
+var errno = Error.getNextAvailableErrno ();
+Error.create (errno, "TEST1", "test 1");
+console.log (Error.get (Error.TEST1));
+console.log (Error.get ("TEST1"));
+console.log (Error.get (errno));
+
+/*
+Prints:
+
+{ [Error: ENOENT]
+ errno: 34,
+ code: "ENOENT",
+ description: "no such file or directory" }
+{ [Error: TEST1] errno: 100, code: "TEST1", description: "test 1" }
+{ [Error: TEST1] errno: 100, code: "TEST1", description: "test 1" }
+{ [Error: TEST1] errno: 100, code: "TEST1", description: "test 1" }
+*/
+```
+
+***
+
+<a name="availability"></a>
+#### Availability [](#start) ####
+
+Via npm:
+
+```
+npm install errno-codes
+```
+
+***
+
+<a name="compatibility"></a>
+#### Compatibility [](#start) ####
+
+✔ Node *
+
+***
+
+<a name="documentation"></a>
+#### Documentation [](#start) ####
+
+[Reference](https://github.com/Gagle/Node-Error/wiki/Reference)
+[Examples](https://github.com/Gagle/Node-Error/tree/master/examples)
+[Change Log](https://github.com/Gagle/Node-Error/wiki/Change-Log)
+[MIT License](https://github.com/Gagle/Node-Error/blob/master/LICENSE)
View
1  old/src/node_modules/errno-codes/error.js
@@ -0,0 +1 @@
+"use strict";var errors={UNKNOWN:{errno:-1,code:"UNKNOWN",description:"unknown error"},OK:{errno:0,code:"OK",description:"success"},EOF:{errno:1,code:"EOF",description:"end of file"},EADDRINFO:{errno:2,code:"EADDRINFO",description:"getaddrinfo error"},EACCES:{errno:3,code:"EACCES",description:"permission denied"},EAGAIN:{errno:4,code:"EAGAIN",description:"no more processes"},EADDRINUSE:{errno:5,code:"EADDRINUSE",description:"address already in use"},EADDRNOTAVAIL:{errno:6,code:"EADDRNOTAVAIL",description:""},EAFNOSUPPORT:{errno:7,code:"EAFNOSUPPORT",description:""},EALREADY:{errno:8,code:"EALREADY",description:""},EBADF:{errno:9,code:"EBADF",description:"bad file descriptor"},EBUSY:{errno:10,code:"EBUSY",description:"resource busy or locked"},ECONNABORTED:{errno:11,code:"ECONNABORTED",description:"software caused connection abort"},ECONNREFUSED:{errno:12,code:"ECONNREFUSED",description:"connection refused"},ECONNRESET:{errno:13,code:"ECONNRESET",description:"connection reset by peer"},EDESTADDRREQ:{errno:14,code:"EDESTADDRREQ",description:"destination address required"},EFAULT:{errno:15,code:"EFAULT",description:"bad address in system call argument"},EHOSTUNREACH:{errno:16,code:"EHOSTUNREACH",description:"host is unreachable"},EINTR:{errno:17,code:"EINTR",description:"interrupted system call"},EINVAL:{errno:18,code:"EINVAL",description:"invalid argument"},EISCONN:{errno:19,code:"EISCONN",description:"socket is already connected"},EMFILE:{errno:20,code:"EMFILE",description:"too many open files"},EMSGSIZE:{errno:21,code:"EMSGSIZE",description:"message too long"},ENETDOWN:{errno:22,code:"ENETDOWN",description:"network is down"},ENETUNREACH:{errno:23,code:"ENETUNREACH",description:"network is unreachable"},ENFILE:{errno:24,code:"ENFILE",description:"file table overflow"},ENOBUFS:{errno:25,code:"ENOBUFS",description:"no buffer space available"},ENOMEM:{errno:26,code:"ENOMEM",description:"not enough memory"},ENOTDIR:{errno:27,code:"ENOTDIR",description:"not a directory"},EISDIR:{errno:28,code:"EISDIR",description:"illegal operation on a directory"},ENONET:{errno:29,code:"ENONET",description:"machine is not on the network"},ENOTCONN:{errno:31,code:"ENOTCONN",description:"socket is not connected"},ENOTSOCK:{errno:32,code:"ENOTSOCK",description:"socket operation on non-socket"},ENOTSUP:{errno:33,code:"ENOTSUP",description:"operation not supported on socket"},ENOENT:{errno:34,code:"ENOENT",description:"no such file or directory"},ENOSYS:{errno:35,code:"ENOSYS",description:"function not implemented"},EPIPE:{errno:36,code:"EPIPE",description:"broken pipe"},EPROTO:{errno:37,code:"EPROTO",description:"protocol error"},EPROTONOSUPPORT:{errno:38,code:"EPROTONOSUPPORT",description:"protocol not supported"},EPROTOTYPE:{errno:39,code:"EPROTOTYPE",description:"protocol wrong type for socket"},ETIMEDOUT:{errno:40,code:"ETIMEDOUT",description:"connection timed out"},ECHARSET:{errno:41,code:"ECHARSET",description:""},EAIFAMNOSUPPORT:{errno:42,code:"EAIFAMNOSUPPORT",description:""},EAISERVICE:{errno:44,code:"EAISERVICE",description:""},EAISOCKTYPE:{errno:45,code:"EAISOCKTYPE",description:""},ESHUTDOWN:{errno:46,code:"ESHUTDOWN",description:""},EEXIST:{errno:47,code:"EEXIST",description:"file already exists"},ESRCH:{errno:48,code:"ESRCH",description:"no such process"},ENAMETOOLONG:{errno:49,code:"ENAMETOOLONG",description:"name too long"},EPERM:{errno:50,code:"EPERM",description:"operation not permitted"},ELOOP:{errno:51,code:"ELOOP",description:"too many symbolic links encountered"},EXDEV:{errno:52,code:"EXDEV",description:"cross-device link not permitted"},ENOTEMPTY:{errno:53,code:"ENOTEMPTY",description:"directory not empty"},ENOSPC:{errno:54,code:"ENOSPC",description:"no space left on device"},EIO:{errno:55,code:"EIO",description:"i/o error"},EROFS:{errno:56,code:"EROFS",description:"read-only file system"},ENODEV:{errno:57,code:"ENODEV",description:"no such device"},ESPIPE:{errno:58,code:"ESPIPE",description:"invalid seek"},ECANCELED:{errno:59,code:"ECANCELED",description:"operation canceled"}},codes={"-1":"UNKNOWN",0:"OK",1:"EOF",2:"EADDRINFO",3:"EACCES",4:"EAGAIN",5:"EADDRINUSE",6:"EADDRNOTAVAIL",7:"EAFNOSUPPORT",8:"EALREADY",9:"EBADF",10:"EBUSY",11:"ECONNABORTED",12:"ECONNREFUSED",13:"ECONNRESET",14:"EDESTADDRREQ",15:"EFAULT",16:"EHOSTUNREACH",17:"EINTR",18:"EINVAL",19:"EISCONN",20:"EMFILE",21:"EMSGSIZE",22:"ENETDOWN",23:"ENETUNREACH",24:"ENFILE",25:"ENOBUFS",26:"ENOMEM",27:"ENOTDIR",28:"EISDIR",29:"ENONET",31:"ENOTCONN",32:"ENOTSOCK",33:"ENOTSUP",34:"ENOENT",35:"ENOSYS",36:"EPIPE",37:"EPROTO",38:"EPROTONOSUPPORT",39:"EPROTOTYPE",40:"ETIMEDOUT",41:"ECHARSET",42:"EAIFAMNOSUPPORT",44:"EAISERVICE",45:"EAISOCKTYPE",46:"ESHUTDOWN",47:"EEXIST",48:"ESRCH",49:"ENAMETOOLONG",50:"EPERM",51:"ELOOP",52:"EXDEV",53:"ENOTEMPTY",54:"ENOSPC",55:"EIO",56:"EROFS",57:"ENODEV",58:"ESPIPE",59:"ECANCELED"},nextAvailableErrno=100;errors.create=function(a,b,c){var d={errno:a,code:b,description:c};errors[b]=d,codes[a]=b},errors.get=function(a,b){var c,d=typeof a;d==="number"?c=errors[codes[a]]:d==="string"?c=errors[a]:c=a;var e=new Error(c.code);e.errno=c.errno,e.code=c.code;var f=c.description;if(b)for(var g in b)f=f.replace(new RegExp("\\{"+g+"\\}","g"),b[g]);return e.description=f,e},errors.getNextAvailableErrno=function(){var a=nextAvailableErrno;return nextAvailableErrno++,a},module.exports=errors;
View
29 old/src/node_modules/errno-codes/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "errno-codes",
+ "version": "1.0.2",
+ "description": "Exposes the errno codes.",
+ "keywords": [
+ "error",
+ "errno"
+ ],
+ "author": {
+ "name": "Gabriel Llamas"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Gagle/Node-Error.git"
+ },
+ "engines": {
+ "node": "*"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://www.opensource.org/licenses/mit-license.html"
+ }
+ ],
+ "main": "error",
+ "readme": "<a name=\"start\"></a>\r\n\r\nNode Error\r\n==========\r\n\r\n_Node.js project_\r\n\r\n#### Exposes the errno codes ####\r\n\r\n[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)\r\n\r\nVersion: 1.0.2\r\n\r\nWhen you are writing a node.js module you\"ll probably deal with errors. If you get a predefined error you can just throw it via a callback but if you want to instantiate a predefined one you need an errno code. Node.js does not expose these errors. Furthermore, they\"re not the standard errno codes. They are defined at [`deps/uv/include/uv.h`](https://github.com/joyent/node/blob/master/deps/uv/include/uv.h).\r\n\r\nThis module eases the error management providing predefined `Error` instances for every errno code and the ability to create customized errors.\r\n\r\n<a name=\"showme\"></a>\r\n#### Show me! [↑](#start) ####\r\n\r\n```javascript\r\nvar Error = require (\"errno-codes\");\r\n\r\nconsole.log (Error.get (Error.ENOENT));\r\n\r\nvar errno = Error.getNextAvailableErrno ();\r\nError.create (errno, \"TEST1\", \"test 1\");\r\nconsole.log (Error.get (Error.TEST1));\r\nconsole.log (Error.get (\"TEST1\"));\r\nconsole.log (Error.get (errno));\r\n\r\n/*\r\nPrints:\r\n\r\n{ [Error: ENOENT]\r\n errno: 34,\r\n code: \"ENOENT\",\r\n description: \"no such file or directory\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n*/\r\n```\r\n\r\n***\r\n\r\n<a name=\"availability\"></a>\r\n#### Availability [↑](#start) ####\r\n\r\nVia npm:\r\n\r\n```\r\nnpm install errno-codes\r\n```\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-Error/wiki/Reference) \r\n[Examples](https://github.com/Gagle/Node-Error/tree/master/examples) \r\n[Change Log](https://github.com/Gagle/Node-Error/wiki/Change-Log) \r\n[MIT License](https://github.com/Gagle/Node-Error/blob/master/LICENSE)",
+ "_id": "errno-codes@1.0.2",
+ "_from": "errno-codes@1.0.2"
+}
View
59 old/test/tests/node_modules/buffered-writer/README.md
@@ -0,0 +1,59 @@
+<a name="start"></a>
+
+Node BufferedWriter
+===================
+
+#### Fully configurable buffered writer for node.js ####
+
+[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
+
+Version: 0.1.12
+
+When you need to write a file you typically write the content in little chunks at a time. To avoid multiple calls to the underlying I/O layer you need to use a piece of memory called "buffer", so instead of writting directly to the disk, you write to the buffer and when it is filled the content is written to disk. Doing this you win performance.
+
+This library allows you to write files using internal buffers, so you don't have to worry about them.
+
+<a name="showme"></a>
+#### Show me! [](#start) ####
+
+```javascript
+var BufferedWriter = require ("buffered-writer");
+
+new BufferedWriter ("file")
+ .on ("error", function (error){
+ console.log (error);
+ })
+
+ .write ([0x00, 0x01, 0x02], 0, 3) //Writes 0x00, 0x01, 0x02
+ .write (new Buffer ([0x03, 0x04]), 1, 1) //Writes 0x04
+ .write (0x0506) //Writes 0x05, 0x06
+ .close ();
+```
+
+***
+
+<a name="availability"></a>
+#### Availability [](#start) ####
+
+Via npm:
+
+```
+npm install buffered-writer
+```
+
+***
+
+<a name="compatibility"></a>
+#### Compatibility [](#start) ####
+
+✔ Node 0.4.10+
+
+***
+
+<a name="documentation"></a>
+#### Documentation [](#start) ####
+
+[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)
+[MIT License](https://github.com/Gagle/Node-BufferedWriter/blob/master/LICENSE)
View
1  old/test/tests/node_modules/buffered-writer/buffered-writer.js
@@ -0,0 +1 @@
+"use strict";var EVENTS=require("events"),FS=require("fs"),Error=require("errno-codes");Error.create(Error.getNextAvailableErrno(),"INVALID_BUFFER_SIZE","The buffer size must be greater than 0.");var BUFFER_SIZE=16384,EOL=process.platform==="win32"?new Buffer([13,10]):new Buffer([10]),toHexArray=function(a){var b=[];do b.unshift(a&255),a>>>=8;while(a);return b},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 Error.get(Error.INVALID_BUFFER_SIZE);this._fileName=a,this._stream=null,this._buffer=null,this._offset=0,this._closing=!1};BufferedWriter.prototype=Object.create(EVENTS.EventEmitter.prototype),BufferedWriter.prototype.constructor=BufferedWriter,BufferedWriter.prototype._flush=function(){this._stream.write(new Buffer(this._offset!==this._settings.bufferSize?this._buffer.slice(0,this._offset):this._buffer)),this._offset=0},BufferedWriter.prototype._write=function(a,b,c){var d=this;this._buffer||(this._buffer=new Buffer(this._settings.bufferSize)),this.touch(d._settings.append);if(c===0)return;var e=c+this._offset>this._settings.bufferSize?this._settings.bufferSize-this._offset:c;a.copy(this._buffer,this._offset,b,b+e),this._offset+=e,b+=e,c-=e,this._offset===this._settings.bufferSize&&(this._flush(),c!==0&&this._write(a,b,c))},BufferedWriter.prototype.close=function(a){if(this._closing||!this._stream)return;a&&(a=a.bind(this)),this._offset!==0&&this._flush();var b=this;this._stream.on("close",function(){b._stream=null,b._buffer=null,b._closing=!1,a&&a()}),this._stream.destroySoon(),this._closing=!0},BufferedWriter.prototype.newLine=function(){return this._write(EOL,0,EOL.length),this},BufferedWriter.prototype.touch=function(a){if(this._closing)return this;a=a||"w";var b=this;return this._stream=FS.createWriteStream(this._fileName,{flags:a,encoding:b._settings.encoding}).on("error",function(a){b.emit("error",a)}),this},BufferedWriter.prototype.write=function(a,b,c){if(this._closing)return this;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{Array.isArray(a)&&(a=new Buffer(a));var e=arguments.length;e===1&&(b=0,c=a.length===0?0:1)}return this._write(a,b,c),this},module.exports=BufferedWriter;
View
71 old/test/tests/node_modules/buffered-writer/node_modules/errno-codes/README.md
@@ -0,0 +1,71 @@
+<a name="start"></a>
+
+Node Error
+==========
+
+_Node.js project_
+
+#### Exposes the errno codes ####
+
+[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
+
+Version: 1.0.2
+
+When you are writing a node.js module you"ll probably deal with errors. If you get a predefined error you can just throw it via a callback but if you want to instantiate a predefined one you need an errno code. Node.js does not expose these errors. Furthermore, they"re not the standard errno codes. They are defined at [`deps/uv/include/uv.h`](https://github.com/joyent/node/blob/master/deps/uv/include/uv.h).
+
+This module eases the error management providing predefined `Error` instances for every errno code and the ability to create customized errors.
+
+<a name="showme"></a>
+#### Show me! [](#start) ####
+
+```javascript
+var Error = require ("errno-codes");
+
+console.log (Error.get (Error.ENOENT));
+
+var errno = Error.getNextAvailableErrno ();
+Error.create (errno, "TEST1", "test 1");
+console.log (Error.get (Error.TEST1));
+console.log (Error.get ("TEST1"));
+console.log (Error.get (errno));
+
+/*
+Prints:
+
+{ [Error: ENOENT]
+ errno: 34,
+ code: "ENOENT",
+ description: "no such file or directory" }
+{ [Error: TEST1] errno: 100, code: "TEST1", description: "test 1" }
+{ [Error: TEST1] errno: 100, code: "TEST1", description: "test 1" }
+{ [Error: TEST1] errno: 100, code: "TEST1", description: "test 1" }
+*/
+```
+
+***
+
+<a name="availability"></a>
+#### Availability [](#start) ####
+
+Via npm:
+
+```
+npm install errno-codes
+```
+
+***
+
+<a name="compatibility"></a>
+#### Compatibility [](#start) ####
+
+✔ Node *
+
+***
+
+<a name="documentation"></a>
+#### Documentation [](#start) ####
+
+[Reference](https://github.com/Gagle/Node-Error/wiki/Reference)
+[Examples](https://github.com/Gagle/Node-Error/tree/master/examples)
+[Change Log](https://github.com/Gagle/Node-Error/wiki/Change-Log)
+[MIT License](https://github.com/Gagle/Node-Error/blob/master/LICENSE)
View
1  old/test/tests/node_modules/buffered-writer/node_modules/errno-codes/error.js
@@ -0,0 +1 @@
+"use strict";var errors={UNKNOWN:{errno:-1,code:"UNKNOWN",description:"unknown error"},OK:{errno:0,code:"OK",description:"success"},EOF:{errno:1,code:"EOF",description:"end of file"},EADDRINFO:{errno:2,code:"EADDRINFO",description:"getaddrinfo error"},EACCES:{errno:3,code:"EACCES",description:"permission denied"},EAGAIN:{errno:4,code:"EAGAIN",description:"no more processes"},EADDRINUSE:{errno:5,code:"EADDRINUSE",description:"address already in use"},EADDRNOTAVAIL:{errno:6,code:"EADDRNOTAVAIL",description:""},EAFNOSUPPORT:{errno:7,code:"EAFNOSUPPORT",description:""},EALREADY:{errno:8,code:"EALREADY",description:""},EBADF:{errno:9,code:"EBADF",description:"bad file descriptor"},EBUSY:{errno:10,code:"EBUSY",description:"resource busy or locked"},ECONNABORTED:{errno:11,code:"ECONNABORTED",description:"software caused connection abort"},ECONNREFUSED:{errno:12,code:"ECONNREFUSED",description:"connection refused"},ECONNRESET:{errno:13,code:"ECONNRESET",description:"connection reset by peer"},EDESTADDRREQ:{errno:14,code:"EDESTADDRREQ",description:"destination address required"},EFAULT:{errno:15,code:"EFAULT",description:"bad address in system call argument"},EHOSTUNREACH:{errno:16,code:"EHOSTUNREACH",description:"host is unreachable"},EINTR:{errno:17,code:"EINTR",description:"interrupted system call"},EINVAL:{errno:18,code:"EINVAL",description:"invalid argument"},EISCONN:{errno:19,code:"EISCONN",description:"socket is already connected"},EMFILE:{errno:20,code:"EMFILE",description:"too many open files"},EMSGSIZE:{errno:21,code:"EMSGSIZE",description:"message too long"},ENETDOWN:{errno:22,code:"ENETDOWN",description:"network is down"},ENETUNREACH:{errno:23,code:"ENETUNREACH",description:"network is unreachable"},ENFILE:{errno:24,code:"ENFILE",description:"file table overflow"},ENOBUFS:{errno:25,code:"ENOBUFS",description:"no buffer space available"},ENOMEM:{errno:26,code:"ENOMEM",description:"not enough memory"},ENOTDIR:{errno:27,code:"ENOTDIR",description:"not a directory"},EISDIR:{errno:28,code:"EISDIR",description:"illegal operation on a directory"},ENONET:{errno:29,code:"ENONET",description:"machine is not on the network"},ENOTCONN:{errno:31,code:"ENOTCONN",description:"socket is not connected"},ENOTSOCK:{errno:32,code:"ENOTSOCK",description:"socket operation on non-socket"},ENOTSUP:{errno:33,code:"ENOTSUP",description:"operation not supported on socket"},ENOENT:{errno:34,code:"ENOENT",description:"no such file or directory"},ENOSYS:{errno:35,code:"ENOSYS",description:"function not implemented"},EPIPE:{errno:36,code:"EPIPE",description:"broken pipe"},EPROTO:{errno:37,code:"EPROTO",description:"protocol error"},EPROTONOSUPPORT:{errno:38,code:"EPROTONOSUPPORT",description:"protocol not supported"},EPROTOTYPE:{errno:39,code:"EPROTOTYPE",description:"protocol wrong type for socket"},ETIMEDOUT:{errno:40,code:"ETIMEDOUT",description:"connection timed out"},ECHARSET:{errno:41,code:"ECHARSET",description:""},EAIFAMNOSUPPORT:{errno:42,code:"EAIFAMNOSUPPORT",description:""},EAISERVICE:{errno:44,code:"EAISERVICE",description:""},EAISOCKTYPE:{errno:45,code:"EAISOCKTYPE",description:""},ESHUTDOWN:{errno:46,code:"ESHUTDOWN",description:""},EEXIST:{errno:47,code:"EEXIST",description:"file already exists"},ESRCH:{errno:48,code:"ESRCH",description:"no such process"},ENAMETOOLONG:{errno:49,code:"ENAMETOOLONG",description:"name too long"},EPERM:{errno:50,code:"EPERM",description:"operation not permitted"},ELOOP:{errno:51,code:"ELOOP",description:"too many symbolic links encountered"},EXDEV:{errno:52,code:"EXDEV",description:"cross-device link not permitted"},ENOTEMPTY:{errno:53,code:"ENOTEMPTY",description:"directory not empty"},ENOSPC:{errno:54,code:"ENOSPC",description:"no space left on device"},EIO:{errno:55,code:"EIO",description:"i/o error"},EROFS:{errno:56,code:"EROFS",description:"read-only file system"},ENODEV:{errno:57,code:"ENODEV",description:"no such device"},ESPIPE:{errno:58,code:"ESPIPE",description:"invalid seek"},ECANCELED:{errno:59,code:"ECANCELED",description:"operation canceled"}},codes={"-1":"UNKNOWN",0:"OK",1:"EOF",2:"EADDRINFO",3:"EACCES",4:"EAGAIN",5:"EADDRINUSE",6:"EADDRNOTAVAIL",7:"EAFNOSUPPORT",8:"EALREADY",9:"EBADF",10:"EBUSY",11:"ECONNABORTED",12:"ECONNREFUSED",13:"ECONNRESET",14:"EDESTADDRREQ",15:"EFAULT",16:"EHOSTUNREACH",17:"EINTR",18:"EINVAL",19:"EISCONN",20:"EMFILE",21:"EMSGSIZE",22:"ENETDOWN",23:"ENETUNREACH",24:"ENFILE",25:"ENOBUFS",26:"ENOMEM",27:"ENOTDIR",28:"EISDIR",29:"ENONET",31:"ENOTCONN",32:"ENOTSOCK",33:"ENOTSUP",34:"ENOENT",35:"ENOSYS",36:"EPIPE",37:"EPROTO",38:"EPROTONOSUPPORT",39:"EPROTOTYPE",40:"ETIMEDOUT",41:"ECHARSET",42:"EAIFAMNOSUPPORT",44:"EAISERVICE",45:"EAISOCKTYPE",46:"ESHUTDOWN",47:"EEXIST",48:"ESRCH",49:"ENAMETOOLONG",50:"EPERM",51:"ELOOP",52:"EXDEV",53:"ENOTEMPTY",54:"ENOSPC",55:"EIO",56:"EROFS",57:"ENODEV",58:"ESPIPE",59:"ECANCELED"},nextAvailableErrno=100;errors.create=function(a,b,c){var d={errno:a,code:b,description:c};errors[b]=d,codes[a]=b},errors.get=function(a,b){var c,d=typeof a;d==="number"?c=errors[codes[a]]:d==="string"?c=errors[a]:c=a;var e=new Error(c.code);e.errno=c.errno,e.code=c.code;var f=c.description;if(b)for(var g in b)f=f.replace(new RegExp("\\{"+g+"\\}","g"),b[g]);return e.description=f,e},errors.getNextAvailableErrno=function(){var a=nextAvailableErrno;return nextAvailableErrno++,a},module.exports=errors;
View
29 old/test/tests/node_modules/buffered-writer/node_modules/errno-codes/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "errno-codes",
+ "version": "1.0.2",
+ "description": "Exposes the errno codes.",
+ "keywords": [
+ "error",
+ "errno"
+ ],
+ "author": {
+ "name": "Gabriel Llamas"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Gagle/Node-Error.git"
+ },
+ "engines": {
+ "node": "*"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://www.opensource.org/licenses/mit-license.html"
+ }
+ ],
+ "main": "error",
+ "readme": "<a name=\"start\"></a>\r\n\r\nNode Error\r\n==========\r\n\r\n_Node.js project_\r\n\r\n#### Exposes the errno codes ####\r\n\r\n[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)\r\n\r\nVersion: 1.0.2\r\n\r\nWhen you are writing a node.js module you\"ll probably deal with errors. If you get a predefined error you can just throw it via a callback but if you want to instantiate a predefined one you need an errno code. Node.js does not expose these errors. Furthermore, they\"re not the standard errno codes. They are defined at [`deps/uv/include/uv.h`](https://github.com/joyent/node/blob/master/deps/uv/include/uv.h).\r\n\r\nThis module eases the error management providing predefined `Error` instances for every errno code and the ability to create customized errors.\r\n\r\n<a name=\"showme\"></a>\r\n#### Show me! [↑](#start) ####\r\n\r\n```javascript\r\nvar Error = require (\"errno-codes\");\r\n\r\nconsole.log (Error.get (Error.ENOENT));\r\n\r\nvar errno = Error.getNextAvailableErrno ();\r\nError.create (errno, \"TEST1\", \"test 1\");\r\nconsole.log (Error.get (Error.TEST1));\r\nconsole.log (Error.get (\"TEST1\"));\r\nconsole.log (Error.get (errno));\r\n\r\n/*\r\nPrints:\r\n\r\n{ [Error: ENOENT]\r\n errno: 34,\r\n code: \"ENOENT\",\r\n description: \"no such file or directory\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n*/\r\n```\r\n\r\n***\r\n\r\n<a name=\"availability\"></a>\r\n#### Availability [↑](#start) ####\r\n\r\nVia npm:\r\n\r\n```\r\nnpm install errno-codes\r\n```\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-Error/wiki/Reference) \r\n[Examples](https://github.com/Gagle/Node-Error/tree/master/examples) \r\n[Change Log](https://github.com/Gagle/Node-Error/wiki/Change-Log) \r\n[MIT License](https://github.com/Gagle/Node-Error/blob/master/LICENSE)",
+ "_id": "errno-codes@1.0.2",
+ "_from": "errno-codes@1.0.2"
+}
View
42 old/test/tests/node_modules/buffered-writer/package.json
@@ -0,0 +1,42 @@
+{
+ "name": "buffered-writer",
+ "version": "0.1.12",
+ "description": "Fully configurable buffered writer.",
+ "keywords": [
+ "buffer",
+ "writer",
+ "line",
+ "write line",
+ "file",
+ "write file",
+ "write text file",
+ "write binary file",
+ "binary"
+ ],
+ "author": {
+ "name": "Gabriel Llamas"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Gagle/Node-BufferedWriter.git"
+ },
+ "engines": {
+ "node": ">=0.4.10"
+ },
+ "dependencies": {
+ "errno-codes": "*"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://www.opensource.org/licenses/mit-license.html"
+ }
+ ],
+ "main": "buffered-writer",
+ "readme": "<a name=\"start\"></a>\r\n\r\nNode BufferedWriter\r\n===================\r\n\r\n#### Fully configurable buffered writer for node.js ####\r\n\r\n[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)\r\n\r\nVersion: 0.1.12\r\n\r\nWhen you need to write a file you typically write the content in little chunks at a time. To avoid multiple calls to the underlying I/O layer you need to use a piece of memory called \"buffer\", so instead of writting directly to the disk, you write to the buffer and when it is filled the content is written to disk. Doing this you win performance.\r\n\r\nThis library allows you to write files using internal buffers, so you don't have to worry about them.\r\n\r\n<a name=\"showme\"></a>\r\n#### Show me! [↑](#start) ####\r\n\r\n```javascript\r\nvar BufferedWriter = require (\"buffered-writer\");\r\n\r\nnew BufferedWriter (\"file\")\r\n\t.on (\"error\", function (error){\r\n\t\tconsole.log (error);\r\n\t})\r\n\t\r\n\t.write ([0x00, 0x01, 0x02], 0, 3) //Writes 0x00, 0x01, 0x02\r\n\t.write (new Buffer ([0x03, 0x04]), 1, 1) //Writes 0x04\r\n\t.write (0x0506) //Writes 0x05, 0x06\r\n\t.close ();\r\n```\r\n\r\n***\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-writer\r\n```\r\n\r\n***\r\n\r\n<a name=\"compatibility\"></a>\r\n#### Compatibility [↑](#start) ####\r\n\r\n✔ Node 0.4.10+\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-BufferedWriter/wiki/Reference) \r\n[Examples](https://github.com/Gagle/Node-BufferedWriter/tree/master/examples) \r\n[Change Log](https://github.com/Gagle/Node-BufferedWriter/wiki/Change-Log) \r\n[MIT License](https://github.com/Gagle/Node-BufferedWriter/blob/master/LICENSE)",
+ "_id": "buffered-writer@0.1.12",
+ "dist": {
+ "shasum": "ed7422fc67e255d91eac999795411cbdd4c66762"
+ },
+ "_from": "buffered-writer@0.1.12"
+}
View
28 package.json
@@ -1,29 +1,23 @@
{
- "name": "buffered-reader",
- "version": "1.0.2",
- "description": "Binary and event-based data buffered readers.",
- "keywords": ["buffer", "reader", "read", "line", "file", "text", "seek",
- "binary"],
+ "name": "binary-reader",
+ "version": "2.0.0",
+ "description": "Random access buffered binary reader",
+ "keywords": ["buffer", "reader", "binary", "file", "seek", "access"],
"author": {
"name": "Gabriel Llamas",
- "email": "gaglekas@gmail.com"
+ "email": "gagle@outlook.com"
},
"repository": {
"type": "git",
- "url": "git://github.com/Gagle/Node-BufferedReader.git"
+ "url": "git://github.com/gagle/node-binary-reader.git"
},
"engines": {
- "node": "*"
- },
- "dependencies": {
- "error-provider": "*"
+ "node": ">=0.10"
},
"devDependencies": {
- "mocha-runner": "*"
+ "speedy": "*",
+ "buffered-reader": "*"
},
- "licenses": [{
- "type": "MIT",
- "url": "http://www.opensource.org/licenses/mit-license.html"
- }],
- "main": "lib/buffered-reader"
+ "license": "MIT",
+ "main": "lib"
}
View
255 readme_wiki.md
@@ -1,255 +0,0 @@
-To use the module:
-
-```javascript
-var reader = require ("buffered-reader");
-var BinaryReader = reader.BinaryReader;
-var DataReader = reader.DataReader;
-```
-
-All the functions that receive a callback are asynchronous and inside them, `this` points to the `DataReader` or `BinaryReader` instance.
-
-<a name="classes"></a>
-### Classes ###
-[`DataReader`](#data-reader) - Reads a file from start to end and emits events like `byte`, `character`, `line` and `buffer`.
-[`BinaryReader`](#binary-reader) - Reads a file using a pointer that can be moved.
-
-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.
-
-Both classes uses an internal buffer so you don't have to worry about buffers.
-
-***
-
-<a name="data-reader"></a>
-# DataReader [](#classes) #
-## Constructor ##
-#### DataReader(fileName, [settings]) ####
-Reads a file from start to end. The reading can be paused resumed or interrupdes at any time. The file is closed automatically when the `end` or `error` event is emitted, so as you can see there's no function to close it explicitly.
-
-__Parameters__
-
-* fileName [`String`]. The file path.
-* settings [`Object`]. An object in literal notation with the settings:
- * bufferSize [`Number`]. The buffer size in bytes. It must be greater than 0. Default: `16KB`.
- * encoding [`String`]. To treat the data as binary this parameter must not be set. If it's a text file, the value must be `"ascii"`, `"utf8"`, `"ucs2"`, `"base64"` or `"hex"`; `"utf8"` is typically used.
-
-<a name="data-reader-custom-errors"></a>
-## Custom errors ##
-
-* `INVALID_BUFFER_SIZE` [`Error`]. `{ errno: <dependent>, code: "INVALID_BUFFER_SIZE", description: "The buffer size must be greater than 0." }`.
-
-<a name="data-reader-events"></a>
-## Events ##
-
-* `"error"` - Emitted when an error occurs. The error is passed as a callback parameter.
-* `"byte"` - Emitted when a byte is read and the encoding has not been configured. The byte and the next byte offset are passed as a callback parameters.
-* `"character"` - Emitted when a character is read and the encoding has been configured. The character and the next byte offset are passed as a callback parameters.
-* `"line"` - Emitted when a line is read and the encoding has been configured. The line (EOL not included) and the next byte offset are passed as a callback parameters.
-* `"buffer"` - Emitted when all the buffer is read. The buffer and the next byte offset are passed as a callback parameters.
-* `"end"` - Emitted when all the file is read or when the reading has been interrupted with [`interrupt()`](#data-reader-interrupt).
-
-The "next byte offset" means that if we have the characters "hi" and we've read "h", the byte offset of "h" is `x` and the next byte offset is `x + 1`, the byte offset of the next character "i". The next byte offset of the last byte, character, line or buffer is `-1`.
-
-<a name="data-reader-functions"></a>
-## Functions ##
-[`DataReader#interrupt()`](#data-reader-interrupt) - Interrupts the reading.
-[`DataReader#pause()`](#data-reader-pause) - Pauses the reading.
-[`DataReader#read()`](#data-reader-read) - Starts reading the file from the beginning to the end.
-[`DataReader#resume()`](#data-reader-resume) - Resumes the reading paused by [`pause()`](#data-reader-pause).
-
-***
-
-<a name="data-reader-interrupt"></a>
-#### DataReader#interrupt() [](#data-reader-functions) ####
-Interrupts the file reading and emits the `end` event. A `buffer` event is also emitted with the buffer content sliced to the current byte offset.
-
-__Example__
-
-```javascript
-new BufferedReader ("file", { encoding: "utf8" })
- .on ("error", function (error){
- console.log (error);
- })
- .on ("character", function (character, nextByteOffset){
- if (character === "c"){
- //"d" and "e" are not read
- this.interrupt ();
- }
- })
- .read ();
-```
-
-file:
-```text
-abcde
-```
-
-***
-
-<a name="data-reader-pause"></a>
-#### DataReader#pause() [](#data-reader-functions) ####
-Pauses the reading. It can be paused at any time.
-
-__Example__
-
-```javascript
-new DataReader ("file", { encoding: "utf8" })
- .on ("error", function (error){
- console.log (error);
- })
- .on ("line", function (line, nextByteOffset){
- if (line === "b"){
- //We wait 3 seconds when we read the line "b"
- this.pause ();
- var me = this;
- setTimeout (function (){
- me.resume ();
- }, 3000);
- }
- })
- .read ();
-```
-
-file:
-```text
-a
-b
-c
-```
-
-***
-
-<a name="data-reader-read"></a>
-#### DataReader#read() [](#data-reader-functions) ####
-Starts reading the file from the beginning to the end.
-
-***
-
-<a name="data-reader-resume"></a>
-#### DataReader#resume() [](#data-reader-functions) ####
-Resumes the reading paused by [`pause()`](#data-reader-pause).
-
-__Example__
-
-See the [`pause()`](#data-reader-pause) example.
-
-***
-
-<a name="binary-reader"></a>
-# BinaryReader[](#classes) #
-## Constructor ##
-#### BinaryReader(fileName, [settings]) ####
-Reads a file using a pointer that can be moved. You can also configure a working window. The limits of the default window are [0, file size - 1]. The window is used to ease the manipulation of the file. If you need to read a portion of a file and you know its limits it's more easier if a window it's used because you can reference the pointer from its start (0) instead of having to reference it from the start of the file.
-
-For example, you have a file but don't know its size, let's suppose size X, range: [0, X-1]. You need to read the last 40 bytes. You have two possible ways to read them.
-* Calculate the size and `seek(X-1-40)`. If you need to seek another position within these 40 bytes you need to reference it from the start of the file taking into account that the file size is variable. If you need to read from byte 10 within these 40 bytes you'll need to do a `seek(X-1-40+10)`. As you can see this can become very messy.
-* Create a window, `{ start: 39, fromEnd: true }` (Note: if `fromEnd` is set to true, the 0 value of the start position is actually the file size minus 1). To read the 10th byte from the last 40 bytes you only need to do a `seek(10)`. `seek(0)` sets the pointer to the start of the window, the byte X-1-40. The file size is computed and all the offsets become relative to the window.
-
-__Parameters__
-
-* fileName [`String`]. The file path.
-* settings [`Object`]. An object in literal notation with the settings:
- * bufferSize [`Number`]. The buffer size in bytes. It must be greater than 0. Default: `16KB`.
- * start [`Number`]. The window start offset. If `fromEnd` is not set or is set to `false` the offset is referenced from the beginning of the file. If it's set to true it's referenced from the end. Default: if `fromEnd` is false, `0`, if `fromEnd` is true, file size - 1.
- * end [`Number`]. The window end offset. If `fromEnd` is not set or is set to `false` the offset is referenced from the beginning of the file. If it's set to true it's referenced from the end. Default: file size - 1.
- * fromEnd [`Boolean`]. If is set to true the start and end offsets are referenced from the start of the file. If is set to false they are referenced from the end of the file.
-
-<a name="binary-reader-constants"></a>
-## Constants ##
-* `BinaryReader.START_OF_WINDOW` [`Object`] - Used to set the offset at the start of the window. It can be used in the `seek()` function.
-* `BinaryReader.END_OF_WINDOW` [`Object`] - Used to set the offset at the end of the window. It can be used in the `seek()` function.
-
-<a name="binary-reader-custom-errors"></a>
-## Custom errors ##
-
-* `INVALID_BUFFER_SIZE` [`Error`]. `{ errno: <dependent>, code: "INVALID_BUFFER_SIZE", description: "The buffer size must be greater than 0." }`.
-* `INVALID_WINDOW_START_OFFSET` [`Error`]. `{ errno: <dependent>, code: "INVALID_WINDOW_START_OFFSET", description: "The start offset must be greater than or equals to 0." }`.
-* `INVALID_WINDOW_END_OFFSET` [`Error`]. `{ errno: <dependent>, code: "INVALID_WINDOW_END_OFFSET", description: "The end offset must be greater than or equals to 0." }`.
-* `INVALID_WINDOW_RANGE_OFFSET` [`Error`]. `{ errno: <dependent>, code: "INVALID_WINDOW_RANGE_OFFSET", description: "The end offset must be greater than or equals to the start`
-`offset and both of them must be inside the file range. Window: [{ws}, {we}], File: [0, {fe}]." }`.
-* `INVALID_SEEK_OFFSET` [`Error`]. `{ errno: <dependent>, code: "INVALID_SEEK_OFFSET", description: "The relative offset must be inside the window range. Relative`
-`offset: {offset}, Relative window: [0, {we}]." }`.
-* `NO_FILE` [`Error`]. `{ errno: <dependent>, code: "NO_FILE", description: "The source is not a file." }`.
-* `EMPTY_FILE` [`Error`]. `{ errno: <dependent>, code: "EMPTY_FILE", description: "The file is empty." }`.
-* `INVALID_READ_BYTES` [`Error`]. `{ errno: <dependent>, code: "INVALID_READ_BYTES", description: "The number of bytes to read must be equal or greater than 1." }`.
-
-<a name="binary-reader-functions"></a>
-## Functions ##
-[`BinaryReader#close(callback)`](#binary-reader-close) - Closes the file.
-[`BinaryReader#getOffset()`](#binary-reader-getOffset) - Returns the current offset.
-[`BinaryReader#isOffsetOutOfWindow()`](#binary-reader-isOffsetOutOfWindow) - Checks whether the offset is beyond the last byte, whether the last byte has been read.
-[`BinaryReader#read(bytes, callback)`](#binary-reader-read) - Reads the given number of bytes.
-[`BinaryReader#seek(offset, callback)`](#binary-reader-seek) - Sets the pointer to the given offset.
-[`BinaryReader#skip(bytes, callback)`](#binary-reader-seek) - Skips the given number of bytes.
-
-A complete example: [id3v1.1.js](https://github.com/Gagle/Node-BufferedReader/blob/master/examples/binary_reader/id3v1.1.js).
-
-***
-
-<a name="binary-reader-close"></a>
-#### BinaryReader#close(callback) [](#binary-reader-functions) ####
-Closes the file.
-
-__Parameters__
-
-* callback [`Function`]. Callback used to notify the result. It gets one parameter, `(error)`:
- * error [`Error`]. Error or `null`.
-
-***
-
-<a name="binary-reader-getOffset"></a>
-#### BinaryReader#getOffset() [](#binary-reader-functions) ####
-Returns the current offset.
-
-__Return__
-
-[`Number`] The offset referenced from the start of the file where the pointer points. It's the next byte to be read.
-
-***
-
-<a name="binary-reader-isOffsetOutOfWindow"></a>
-#### BinaryReader#isOffsetOutOfWindow() [](#binary-reader-functions) ####
-Checks whether the offset is beyond the last byte, whether the last byte has been read. If the file has a size of X bytes and the offset is at byte X-1 (last byte) and you read 1 or more bytes, the offset will be placed outside the window to indicate that the last byte has been read and it's not possible to perfom a skip or read operation.
-
-__Return__
-
-[`Boolean`] `true` if the offset is outside the window, `false` otherwise.
-
-***
-
-<a name="binary-reader-read"></a>
-#### BinaryReader#read(bytes, callback) [](#binary-reader-functions) ####
-Reads the given number of bytes.
-
-__Parameters__
-
-* bytes [`Number`]. Number of bytes to read.
-* callback [`Function`]. Callback used to notify the result. It gets three parameters, `(error, bytes, bytesRead)`:
- * error [`Error`]. Error or `null`.
- * bytes [`Buffer`]. Buffer with the bytes that has been read or `null` if error.
- * bytesRead [`Number`]. The number of bytes that has been read.
-
-
-***
-
-<a name="binary-reader-seek"></a>
-#### BinaryReader#seek(offset, callback) [](#binary-reader-functions) ####
-Sets the pointer to the given offset. The next read operation will start from this offset.
-
-__Parameters__
-
-* offset [`Number`]. The offset to set the pointer.
-* callback [`Function`]. Callback used to notify the result. It gets one parameter, `(error)`:
- * error [`Error`]. Error or `null`.
-
-***
-
-<a name="binary-reader-skip"></a>
-#### BinaryReader#skip(bytes, callback) [](#binary-reader-functions) ####
-Skips the given number of bytes. This basically moves the pointer forwards or backwards (it's possible to skip a negative number of bytes).
-
-__Parameters__
-
-* offset [`Number`]. The offset to set the pointer.
-* callback [`Function`]. Callback used to notify the result. It gets two parameters, `(error, bytesSkipped)`:
- * error [`Error`]. Error or `null`.
- * bytesSkipped [`Number`]. The number of bytes skipped.
View
12 tests/binary-reader/binary-reader.js
@@ -1,12 +0,0 @@
-"use strict";
-
-var ASSERT = require ("assert");
-var FS = require ("fs");
-var br = require ("../../lib/buffered-reader").BinaryReader;
-
-var WIN = process.platform === "win32";
-var BINARY_READER = "binary-reader/";
-
-describe ("binary-reader", function (){
-
-});
View
438 tests/data-reader/data-reader.js
@@ -1,438 +0,0 @@
-"use strict";
-
-var ASSERT = require ("assert");
-var FS = require ("fs");
-var dr = require ("../../lib/buffered-reader").DataReader;
-
-var WIN = process.platform === "win32";
-var DATA_READER = "data-reader/";
-
-describe ("data-reader", function (){
- describe ("open", function (){
- it ("should throw an INVALID_BUFFER_SIZE exception if the buffer size is " +
- "not positive", function (done){
- ASSERT.throws (function (){
- dr.open ("file", { bufferSize: -1 });
- }, function (error){
- return error.code === "INVALID_BUFFER_SIZE";
- });
- done ();
- });
- });
-
- describe ("read", function (){
- it ("should emit a BINARY_DATA error when a character or line listeners " +
- "are added and the file is read as a binary data", function (done){
- dr.open ("file")
- .on ("error", function (error){
- ASSERT.ok (error.code === "BINARY_DATA");
-
- dr.open ("file")
- .on ("error", function (error){
- ASSERT.ok (error.code === "BINARY_DATA");
- done ();
- })
- .on ("line", function (){})
- .on ("end", function (){
- ASSERT.fail ();
- })
- .read ();
- })
- .on ("character", function (){})
- .on ("end", function (){
- ASSERT.fail ();
- })
- .read ();
- });
-
- it ("should not emit any buffer event if the file size is 0",
- function (done){
- FS.writeFile (DATA_READER + "file", "", "utf8", function (error){
- if (error) return done (error);
- var exe = false;
- dr.open (DATA_READER + "file")
- .on ("buffer", function (buffer){
- exe = true;
- })
- .on ("end", function (){
- ASSERT.ok (!exe);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit buffer events", function (done){
- FS.writeFile (DATA_READER + "file", "abc", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { bufferSize: 1 })
- .on ("buffer", function (buffer){
- n++;
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit byte events", function (done){
- FS.writeFile (DATA_READER + "file", "", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file")
- .on ("byte", function (b){
- n++;
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit character events", function (done){
- FS.writeFile (DATA_READER + "file", "", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { encoding: "utf8" })
- .on ("character", function (c){
- n++;
- })
- .on ("end", function (){
- ASSERT.equal (n, 1);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit line events, empty lines, big buffer", function (done){
- FS.writeFile (DATA_READER + "file", "\n\n\n", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { encoding: "utf8" })
- .on ("line", function (line){
- n++;
- ASSERT.equal (line, "");
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit line events, not empty lines, big buffer", function (done){
- FS.writeFile (DATA_READER + "file", "1\n2\n3\n", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { encoding: "utf8" })
- .on ("line", function (line){
- n++;
- ASSERT.equal (line, n.toString ());
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit line events, no last \\n, big buffer", function (done){
- FS.writeFile (DATA_READER + "file", "1\n2\n3", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { encoding: "utf8" })
- .on ("line", function (line){
- n++;
- ASSERT.equal (line, n.toString ());
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit line events, no \\n, big buffer", function (done){
- FS.writeFile (DATA_READER + "file", "abc", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { encoding: "utf8" })
- .on ("line", function (line){
- n++;
- ASSERT.equal (line, "abc");
- })
- .on ("end", function (){
- ASSERT.equal (n, 1);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit line events, empty lines, little buffer", function (done){
- FS.writeFile (DATA_READER + "file", "\n\n\n", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { encoding: "utf8", bufferSize: 1 })
- .on ("line", function (line){
- n++;
- ASSERT.equal (line, "");
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit line events, not empty lines, little buffer",
- function (done){
- FS.writeFile (DATA_READER + "file", "1\n2\n3\n", "utf8",
- function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { encoding: "utf8",
- bufferSize: 1 })
- .on ("line", function (line){
- n++;
- ASSERT.equal (line, n.toString ());
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit line events, no last \\n, little buffer", function (done){
- FS.writeFile (DATA_READER + "file", "1\n2\n3", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { encoding: "utf8", bufferSize: 1 })
- .on ("line", function (line){
- n++;
- ASSERT.equal (line, n.toString ());
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- done ();
- })
- .read ();
- });
- });
-
- it ("should emit line events, no \\n, little buffer", function (done){
- FS.writeFile (DATA_READER + "file", "abc", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { encoding: "utf8", bufferSize: 1 })
- .on ("line", function (line){
- n++;
- ASSERT.equal (line, "abc");
- })
- .on ("end", function (){
- ASSERT.equal (n, 1);
- done ();
- })
- .read ();
- });
- });
-
- afterEach (function (done){
- FS.exists (DATA_READER + "file", function (exists){
- if (exists){
- FS.unlink (DATA_READER + "file", done);
- }else{
- done ();
- }
- });
- });
- });
-
- describe ("pause/resume", function (){
- it ("should pause at the end of the file, just before the end event is " +
- "emitted, and when resume is called the end event is emitted",
- function (done){
- FS.writeFile (DATA_READER + "file", "abc", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- var paused = false;
- dr.open (DATA_READER + "file", { bufferSize: 1 })
- .on ("buffer", function (buffer){
- n++;
- if (n === 3){
- this.pause ();
- paused = true;
- var me = this;
- setTimeout (function (){
- me.resume ();
- }, 1);
- }
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- ASSERT.ok (paused);
- done ();
- })
- .read ();
- });
- });
-
- it ("the internal buffer must be null when the reader is paused after a" +
- "buffer event", function (done){
- FS.writeFile (DATA_READER + "file", "abc", "utf8", function (error){
- if (error) return done (error);
- dr.open (DATA_READER + "file", { bufferSize: 1 })
- .on ("buffer", function (buffer){
- ASSERT.ok (this._buffer === null);
- })
- .on ("end", function (){
- done ();
- })
- .read ();
- });
- });
-
- it ("should pause and resume buffer events", function (done){
- FS.writeFile (DATA_READER + "file", "abc", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- dr.open (DATA_READER + "file", { bufferSize: 1 })
- .on ("buffer", function (buffer){
- n++;
- if (n === 2){
- this.pause ();
- var me = this;
- setTimeout (function (){
- me.resume ();
- }, 1);
- }
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- done ();
- })
- .read ();
- });
- });
-
- it ("should pause and resume byte events", function (done){
- FS.writeFile (DATA_READER + "file", "", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- var paused = false;
- var nextByte;
- dr.open (DATA_READER + "file")
- .on ("byte", function (b, next){
- n++;
- if (n === 2){
- this.pause ();
- var me = this;
- setTimeout (function (){
- ASSERT.ok (me._buffer !== null);
- ASSERT.ok (me._start === 2);
- me.resume ();
- }, 1);
- }else if (n === 3){
- ASSERT.equal (b, 0x91);
- }
- nextByte = next;
- })
- .on ("end", function (){
- ASSERT.equal (n, 3);
- ASSERT.equal (nextByte, -1);
- done ();
- })
- .read ();
- });
- });
-
- it ("should pause and resume line events, middle line and before end",
- function (done){
- FS.writeFile (DATA_READER + "file", "abc", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- var paused = false;
- var linePause = false;
- dr.open (DATA_READER + "file", { encoding: "utf8" })
- .on ("character", function (c){
- if (c === "b"){
- this.pause ();
- paused = true;
- var me = this;
- setTimeout (function (){
- me.resume ();
- }, 1);
- }
- })
- .on ("line", function (buffer){
- ASSERT.ok (paused);
- this.pause ();
- linePause = true;
- var me = this;
- setTimeout (function (){
- me.resume ();
- }, 1);
- })
- .on ("end", function (){
- ASSERT.ok (linePause);
- done ();
- })
- .read ();
- });
- });
-
- afterEach (function (done){
- FS.exists (DATA_READER + "file", function (exists){
- if (exists){
- FS.unlink (DATA_READER + "file", done);
- }else{
- done ();
- }
- });
- });
- });
-
- describe ("stop", function (){
- it ("should stop anything", function (done){
- FS.writeFile (DATA_READER + "file", "", "utf8", function (error){
- if (error) return done (error);
- var n = 0;
- var paused = false;
- dr.open (DATA_READER + "file")
- .on ("byte", function (b){
- n++;
- if (n === 2){
- this.stop ();
- }
- })
- .on ("end", function (){
- ASSERT.equal (n, 2);
- done ();
- })
- .read ();
- });
- });
-
- afterEach (function (done){
- FS.exists (DATA_READER + "file", function (exists){
- if (exists){
- FS.unlink (DATA_READER + "file", done);
- }else{
- done ();
- }
- });
- });
- });
-});
View
10 tests/run.js
@@ -1,10 +0,0 @@
-"use strict";
-
-var Runner = require ("mocha-runner");
-
-new Runner ({
- exclude: ["binary-reader", "data-reader"],
- tests: ["binary-reader/binary-reader.js", "data-reader/data-reader.js"]
-}).run (function (error){
- if (error) console.log (error);
-});
Please sign in to comment.