Permalink
Browse files

don't know what is this

  • Loading branch information...
1 parent 8312e6c commit 5a995a3f9a8ed19be0a1b38eaacd5e90f2cf7382 Gabriel Llamas committed Aug 8, 2013
Showing with 1,825 additions and 486 deletions.
  1. +1 −2 .gitignore
  2. +5 −0 .npmignore
  3. +82 −0 CHANGES
  4. +1 −1 LICENSE
  5. +226 −74 README.md
  6. +0 −71 build/node_modules/errno-codes/README.md
  7. +0 −1 build/node_modules/errno-codes/error.js
  8. +0 −32 build/node_modules/errno-codes/package.json
  9. +428 −0 lib/binary-reader.js
  10. +6 −0 lib/buffered-reader.js
  11. +205 −0 lib/data-reader.js
  12. +2 −0 old/.gitignore
  13. +21 −0 old/LICENSE
  14. +103 −0 old/README.md
  15. 0 { → old}/build/buffered-reader.js
  16. 0 { → old}/examples/all-in-one.js
  17. 0 { → old}/examples/binary_reader/id3v1.1.js
  18. 0 { → old}/examples/binary_reader/id3v1.1.mp3
  19. 0 { → old}/examples/data_reader/united_states_constitution
  20. 0 { → old}/examples/data_reader/united_states_constitution.js
  21. 0 { → old}/examples/lorem ipsum
  22. +1 −1 { → old}/src/buffered-reader.js
  23. 0 { → old}/test/playground.js
  24. 0 { → old}/test/tests/binary_reader_file
  25. 0 { → old}/test/tests/binary_reader_read.js
  26. 0 { → old}/test/tests/binary_reader_seek.js
  27. 0 { → old}/test/tests/binary_reader_skip.js
  28. 0 { → old}/test/tests/data_reader_file
  29. 0 { → old}/test/tests/data_reader_read.js
  30. 0 { → old}/test/tests/data_reader_unicode
  31. 0 { → old}/test/tests/data_reader_unicode.js
  32. +29 −0 package.json
  33. +255 −0 readme_wiki.md
  34. +0 −71 src/node_modules/errno-codes/README.md
  35. +0 −1 src/node_modules/errno-codes/error.js
  36. +0 −29 src/node_modules/errno-codes/package.json
  37. +0 −59 test/tests/node_modules/buffered-writer/README.md
  38. +0 −1 test/tests/node_modules/buffered-writer/buffered-writer.js
  39. +0 −71 test/tests/node_modules/buffered-writer/node_modules/errno-codes/README.md
  40. +0 −1 test/tests/node_modules/buffered-writer/node_modules/errno-codes/error.js
  41. +0 −29 test/tests/node_modules/buffered-writer/node_modules/errno-codes/package.json
  42. +0 −42 test/tests/node_modules/buffered-writer/package.json
  43. +12 −0 tests/binary-reader/binary-reader.js
  44. +438 −0 tests/data-reader/data-reader.js
  45. +10 −0 tests/run.js
View
3 .gitignore
@@ -1,2 +1 @@
-doc
-manage
+node_modules
View
5 .npmignore
@@ -0,0 +1,5 @@
+node_modules
+tests
+.npmignore
+CHANGES
+LICENSE
View
82 CHANGES
@@ -0,0 +1,82 @@
+v1.1.0 (xx Jan 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.
+
+v1.0.0 (04 Oct 2012)
+ Complete code refactor for better maintenance.
+ New classes "DataReader" and "BinaryReader". The "BufferedReader" class has
+ been deprecated.
+ Added new functions to "BinaryReader": "getOffset()" and
+ "isOffsetOutOfWindow()".
+ The "skip" function can move the offset backwards; a negative number of bytes
+ can be skipped.
+ Added constants to move the offset to the start and end of window:
+ "BinaryReader.START_OF_WINDOW", "BinaryReader.END_OF_WINDOW".
+ Added new setting to the "BinaryReader" constructor: "fromEnd".
+ Some bug fixes.
+
+v0.2.7 (17 Aug 2012)
+ Updated errno-codes module.
+
+v0.2.6 (05 Aug 2012)
+ Better error management.
+
+v0.2.5 (25 Jul 2012)
+ The buffered reader is closed automatically on error. There's no need to
+ close it again from outside.
+
+v0.2.4 (25 Jul 2012)
+ Fixed the byte offset in the "buffer" event when only a "buffer" event was
+ set.
+ Fixed the last byte offset of any data event. Now the last byte offset is -1.
+ Added "pause()" and "resume()".
+
+v0.2.3 (16 May 2012)
+ Improved "read()" performance when the line event is not configured.
+
+v0.2.2 (13 May 2012)
+ Added a "byteOffset" parameter to the callback of emitted "byte", "character",
+ "line" and "buffer" events.
+
+v0.2.1 (13 May 2012)
+ Improved "read()" performance.
+
+v0.2.0 (02 May 2012)
+ Fixed some bugs when the buffer had the same or less size than the bytes to
+ read.
+ Now the constructor receives an object in literal notation for the settings.
+ Added start and end offsets parameters for limitting the range of the read.
+ Added a "seek()" function for moving the file cursor for the next reading
+ operation.
+ Improved "skip()" performance. Now it calls to "seek()" function with the
+ appropriate offset instead of reading the content into the buffer trying
+ to simulate a jump.
+
+v0.1.2 (29 Apr 2012)
+ Added "skip()" function to skip bytes.
+
+v0.1.1 (25 Apr 2012)
+ Added "interrupt()" function to stop the file reading started with "read()".
+
+v0.1.0 (25 Apr 2012)
+ New feature. Now it's possible to read a chunk of bytes using internal
+ buffers.
+
+v0.0.6 (21 Apr 2012)
+ Changed the way the module is required. Now can be required using
+ "var BufferedReader = require ("buffered-reader");"
+
+v0.0.5 (16 Apr 2012)
+ Removed "getFileName()" internal function.
+
+v0.0.4 (12 Apr 2012)
+ "read()" can be called multiple times with the same "BufferedReader" instance.
+
+v0.0.3 (11 Apr 2012)
+ Fixed bug with Windows end of lines.
+
+v0.0.2 (11 Apr 2012)
+ First commit.
View
2 LICENSE
@@ -1,6 +1,6 @@
MIT License.
-Copyright (c) 2012. Gabriel Llamas.
+Copyright (c) 2012+. Gabriel Llamas.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
300 README.md
@@ -1,103 +1,255 @@
-<a name="start"></a>
+To use the module:
-Node BufferedReader
-===================
+```javascript
+var reader = require ("buffered-reader");
+var BinaryReader = reader.BinaryReader;
+var DataReader = reader.DataReader;
+```
-_Node.js project_
+All the functions that receive a callback are asynchronous and inside them, `this` points to the `DataReader` or `BinaryReader` instance.
-#### Binary and event-based data buffered readers ####
+<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.
-[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
+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.
-Version: 1.0.1
+Both classes uses an internal buffer so you don't have to worry about buffers.
-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="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.
-<a name="showme"></a>
-#### Show me! [](#start) ####
+__Parameters__
-```javascript
-var reader = require ("buffered-reader");
-var BinaryReader = reader.BinaryReader;
-var DataReader = reader.DataReader;
+* 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).
-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 ();
+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
-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.
+abcde
```
***
-<a name="availability"></a>
-#### Availability [](#start) ####
+<a name="data-reader-pause"></a>
+#### DataReader#pause() [](#data-reader-functions) ####
+Pauses the reading. It can be paused at any time.
-Via npm:
+__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 ();
```
-npm install buffered-reader
+
+file:
+```text
+a
+b
+c
```
***
-<a name="compatibility"></a>
-#### Compatibility [](#start) ####
+<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__
-✔ Node *
+See the [`pause()`](#data-reader-pause) example.
***
-<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)
+<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
71 build/node_modules/errno-codes/README.md
@@ -1,71 +0,0 @@
-<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 build/node_modules/errno-codes/error.js
@@ -1 +0,0 @@
-"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 build/node_modules/errno-codes/package.json
@@ -1,32 +0,0 @@
-{
- "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
428 lib/binary-reader.js
@@ -0,0 +1,428 @@
+"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
@@ -0,0 +1,6 @@
+"use strict";
+
+module.exports = {
+ DataReader: require ("./data-reader"),
+ BinaryReader: require ("./binary-reader"),
+};
View
205 lib/data-reader.js
@@ -0,0 +1,205 @@
+"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 old/.gitignore
@@ -0,0 +1,2 @@
+doc
+manage
View
21 old/LICENSE
@@ -0,0 +1,21 @@
+MIT License.
+
+Copyright (c) 2012+. Gabriel Llamas.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
103 old/README.md
@@ -0,0 +1,103 @@
+<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)
View
0 build/buffered-reader.js → old/build/buffered-reader.js
File renamed without changes.
View
0 examples/all-in-one.js → old/examples/all-in-one.js
File renamed without changes.
View
0 examples/binary_reader/id3v1.1.js → old/examples/binary_reader/id3v1.1.js
File renamed without changes.
View
0 examples/binary_reader/id3v1.1.mp3 → old/examples/binary_reader/id3v1.1.mp3
File renamed without changes.
View
0 ...es/data_reader/united_states_constitution → ...es/data_reader/united_states_constitution
File renamed without changes.
View
0 ...data_reader/united_states_constitution.js → ...data_reader/united_states_constitution.js
File renamed without changes.
View
0 examples/lorem ipsum → old/examples/lorem ipsum
File renamed without changes.
View
2 src/buffered-reader.js → old/src/buffered-reader.js
@@ -428,7 +428,7 @@ BinaryReader.prototype.getOffset = function (){
};
BinaryReader.prototype.isOffsetOutOfWindow = function (){
- return this._globalOffset == -1;
+ return this._globalOffset === -1;
};
BinaryReader.prototype.read = function (bytes, cb){
View
0 test/playground.js → old/test/playground.js
File renamed without changes.
View
0 test/tests/binary_reader_file → old/test/tests/binary_reader_file
File renamed without changes.
View
0 test/tests/binary_reader_read.js → old/test/tests/binary_reader_read.js
File renamed without changes.
View
0 test/tests/binary_reader_seek.js → old/test/tests/binary_reader_seek.js
File renamed without changes.
View
0 test/tests/binary_reader_skip.js → old/test/tests/binary_reader_skip.js
File renamed without changes.
View
0 test/tests/data_reader_file → old/test/tests/data_reader_file
File renamed without changes.
View
0 test/tests/data_reader_read.js → old/test/tests/data_reader_read.js
File renamed without changes.
View
0 test/tests/data_reader_unicode → old/test/tests/data_reader_unicode
File renamed without changes.
View
0 test/tests/data_reader_unicode.js → old/test/tests/data_reader_unicode.js
File renamed without changes.
View
29 package.json
@@ -0,0 +1,29 @@
+{
+ "name": "buffered-reader",
+ "version": "1.0.2",
+ "description": "Binary and event-based data buffered readers.",
+ "keywords": ["buffer", "reader", "read", "line", "file", "text", "seek",
+ "binary"],
+ "author": {
+ "name": "Gabriel Llamas",
+ "email": "gaglekas@gmail.com"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Gagle/Node-BufferedReader.git"
+ },
+ "engines": {
+ "node": "*"
+ },
+ "dependencies": {
+ "error-provider": "*"
+ },
+ "devDependencies": {
+ "mocha-runner": "*"
+ },
+ "licenses": [{
+ "type": "MIT",
+ "url": "http://www.opensource.org/licenses/mit-license.html"
+ }],
+ "main": "lib/buffered-reader"
+}
View
255 readme_wiki.md
@@ -0,0 +1,255 @@
+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
71 src/node_modules/errno-codes/README.md
@@ -1,71 +0,0 @@
-<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 src/node_modules/errno-codes/error.js
@@ -1 +0,0 @@
-"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 src/node_modules/errno-codes/package.json
@@ -1,29 +0,0 @@
-{
- "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 test/tests/node_modules/buffered-writer/README.md
@@ -1,59 +0,0 @@
-<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 test/tests/node_modules/buffered-writer/buffered-writer.js
@@ -1 +0,0 @@
-"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 test/tests/node_modules/buffered-writer/node_modules/errno-codes/README.md
@@ -1,71 +0,0 @@
-<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 test/tests/node_modules/buffered-writer/node_modules/errno-codes/error.js
@@ -1 +0,0 @@
-"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 test/tests/node_modules/buffered-writer/node_modules/errno-codes/package.json
@@ -1,29 +0,0 @@
-{
- "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 test/tests/node_modules/buffered-writer/package.json
@@ -1,42 +0,0 @@
-{
- "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
12 tests/binary-reader/binary-reader.js
@@ -0,0 +1,12 @@
+"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
@@ -0,0 +1,438 @@
+"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",