Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
api: complete rewrite base on buffer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 9, 2018
1 parent e0cbcc8 commit ebdbd72
Show file tree
Hide file tree
Showing 42 changed files with 2,056 additions and 2,376 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@

# Changelog

## Trunk

This is a complete rewrite based with a Buffer implementation. There are no major breaking changes but it introduces a multiple minor breaking changes:

* count is now info.records
* drop the record event
* normalize error message as `{error type}: {error description}`
* state values are now isolated into the `info` object
* `count` is now `info.records`
* `lines` is now `info.lines`
* `empty_line_count` is now `info.empty_line_count`
* `skipped_line_count` is now `info.skipped_line_count`
* `context.count` is cast function is now `context.records`
* drop support for options `auto_parse` and `auto_parse_date`
* drop emission of the `record` event
* in raw option, the `raw` property is renamed `record`

API management

* Multiple tests have been rewritten with easier data sample
* Source code is now written in ES6 instead of CoffeeScript

## Version 3.2.0

* max_limit_on_data_read: update error msg
Expand Down
43 changes: 43 additions & 0 deletions lib/ResizeableBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@


class ResizeableBuffer{
constructor(size=100){
this.size = size
this.length = 0
this.buf = Buffer.alloc(size)
}
prepend(val){
const length = this.length++
if(length === this.size){
this.resize()
}
const buf = this.clone()
this.buf[0] = val
buf.copy(this.buf,1, 0, length)
}
append(val){
const length = this.length++
if(length === this.size){
this.resize()
}
this.buf[length] = val
}
clone(){
return Buffer.from(this.buf.slice(0, this.length))
}
resize(){
const length = this.length
this.size = this.size * 2
const buf = Buffer.alloc(this.size)
this.buf.copy(buf,0, 0, length)
this.buf = buf
}
toString(){
return this.buf.slice(0, this.length).toString()
}
reset(){
this.length = 0
}
}

module.exports = ResizeableBuffer
75 changes: 75 additions & 0 deletions lib/es5/ResizeableBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use strict";

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

var ResizeableBuffer =
/*#__PURE__*/
function () {
function ResizeableBuffer() {
var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;

_classCallCheck(this, ResizeableBuffer);

this.size = size;
this.length = 0;
this.buf = Buffer.alloc(size);
}

_createClass(ResizeableBuffer, [{
key: "prepend",
value: function prepend(val) {
var length = this.length++;

if (length === this.size) {
this.resize();
}

var buf = this.clone();
this.buf[0] = val;
buf.copy(this.buf, 1, 0, length);
}
}, {
key: "append",
value: function append(val) {
var length = this.length++;

if (length === this.size) {
this.resize();
}

this.buf[length] = val;
}
}, {
key: "clone",
value: function clone() {
return Buffer.from(this.buf.slice(0, this.length));
}
}, {
key: "resize",
value: function resize() {
var length = this.length;
this.size = this.size * 2;
var buf = Buffer.alloc(this.size);
this.buf.copy(buf, 0, 0, length);
this.buf = buf;
}
}, {
key: "toString",
value: function toString() {
return this.buf.slice(0, this.length).toString();
}
}, {
key: "reset",
value: function reset() {
this.length = 0;
}
}]);

return ResizeableBuffer;
}();

module.exports = ResizeableBuffer;
Loading

0 comments on commit ebdbd72

Please sign in to comment.