-module.exports = function Chunker(data, breakString, chunkSize) {
// Divides `data` into chunks of `chunkSize` for faster processing
- var chunks = [];
+var Chunker = function Chunker(data, breakString, chunkSize) {
+ this.chunks = [];
+
for (var cursor = 0, dataSize = data.length; cursor < dataSize;) {
var nextCursor = cursor + chunkSize > dataSize ?
dataSize - 1 :
if (nextCursor == -1)
nextCursor = data.length - 1;
- chunks.push(data.substring(cursor, nextCursor + breakString.length));
+ this.chunks.push(data.substring(cursor, nextCursor + breakString.length));
cursor = nextCursor + breakString.length;
}
+};
- return {
- isEmpty: function() {
- return chunks.length === 0;
- },
+Chunker.prototype.isEmpty = function () {
+ return this.chunks.length === 0;
+};
- next: function() {
- return chunks.shift();
- }
- };
+Chunker.prototype.next = function () {
+ return this.chunks.shift();
};
+
+module.exports = Chunker;