Skip to content
Browse files

Comments

  • Loading branch information...
1 parent f00c8d0 commit e1016aa894d202f490f8deff9e88fc4f65af745e @janjongboom janjongboom committed Dec 28, 2011
Showing with 18 additions and 1 deletion.
  1. +2 −1 janzip/janzip.js
  2. +16 −0 janzip/rollingbuffer.js
View
3 janzip/janzip.js
@@ -1,7 +1,8 @@
/**
* node.js zipping module
*
- * (c) Jan Jongboom, 2011
+ * Authors:
+ * Jan Jongboom <janjongboom@gmail.com>
*/
var RollingBuffer = require("./rollingbuffer");
var fs = require("fs");
View
16 janzip/rollingbuffer.js
@@ -1,14 +1,25 @@
+/**
+ * This a MemoryStream like structure for node.js based on an internal Buffer.
+ * It's currently written to be write heavy, read once.
+ *
+ * Authors:
+ * Jan Jongboom <janjongboom@gmail.com>
+ */
function RollingBuffer (arg0, arg1, arg2) {
+ // current offset
var offset = 0x00;
+ // internal buffer
this.buf = new Buffer(arg0, arg1, arg2); // make this nice :)
this.length = this.buf.length;
+ // write a string
this.write = function (str, encoding) {
var written = this.buf.write(str, offset, encoding);
offset += written;
};
+ // write another buffer
this.appendBuffer = function (newBuffer) {
if (newBuffer instanceof Buffer) {
newBuffer.copy(this.buf, offset);
@@ -20,22 +31,26 @@ function RollingBuffer (arg0, arg1, arg2) {
}
};
+ // write buffer to string
this.toString = function (encoding) {
return this.buf.toString(encoding);
};
+ // write 1 byte
this.writeInt8 = function (data) {
this.buf[offset] = data;
offset += 1;
};
+ // write 2 bytes
this.writeInt16 = function (data) {
this.buf[offset] = data & 0xff;
this.buf[offset + 1] = (data & 0xff00) >> 8;
offset += 2;
};
+ // write 4 bytes
this.writeInt32 = function (data) {
this.buf[offset] = data & 0xff;
this.buf[offset + 1] = (data & 0xff00) >> 0x08;
@@ -45,6 +60,7 @@ function RollingBuffer (arg0, arg1, arg2) {
offset += 4;
};
+ // return inner buffer
this.getInternalBuffer = function () {
return this.buf;
};

0 comments on commit e1016aa

Please sign in to comment.
Something went wrong with that request. Please try again.