initial commit

This commit is contained in:
dude
2026-09-01 18:33:56 +00:00
commit c24449ee0a
2761 changed files with 302737 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Environment variable files
.envrc
.env
# Temporary / data folders
.tmp
data/
# Source directory
src/
# Test directory
test/
.eslintrc
.babelrc
+6
View File
@@ -0,0 +1,6 @@
sudo: false
language: node_js
notifications:
email: false
node_js:
- 6
+20
View File
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2016 Olivier Lalonde <olalonde@gmail.com>
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.
+47
View File
@@ -0,0 +1,47 @@
# meterstream
[![Build Status](https://travis-ci.org/blockai/meterstream.svg?branch=master)](https://travis-ci.org/blockai/meterstream)
Transform stream that emits a `MeterStream.OverflowError` error if it has
read more than `maxBytes` bytes.
Note: if more than `maxBytes` is read, the transform will ensure that
exactly `maxBytes` have been flushed to the readable side before
emitting the OverflowError.
## Install
```bash
npm install --save meterstream
```
Requires Node v6+
## Usage
**new MeterStream(maxBytes = Infinity)**
Returns a pass through stream where `maxBytes` (defaults to `Infinity`)
is the max number of bytes to pass through before emitting an error.
See [./test](./test) directory for usage examples.
```javascript
import MeterStream from 'meterstream'
process.stdin
.pipe(new MeterStream(5))
.on('error', (err) => {
console.error('Read more than 5 bytes from stdin')
console.error(err)
process.exit(1)
})
.pipe(process.stdout)
// echo -n "123456789" | babel-node src/demo.js
// 12345Read more than 5 bytes from stdin
// Error: Stream exceeded specified max of 5 bytes.
// at OverflowError (...)
// at ....
```
+13
View File
@@ -0,0 +1,13 @@
'use strict';
var _ = require('./');
var _2 = _interopRequireDefault(_);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
process.stdin.pipe(new _2.default(5)).on('error', err => {
console.error('Read more than 5 bytes from stdin');
console.error(err);
process.exit(1);
}).pipe(process.stdout); /* eslint-disable no-console */
+42
View File
@@ -0,0 +1,42 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _stream = require('stream');
class OverflowError extends Error {}
class MeterSream extends _stream.Transform {
constructor() {
let maxSize = arguments.length <= 0 || arguments[0] === undefined ? Infinity : arguments[0];
super();
this.maxSize = maxSize;
this.byteCount = 0;
}
_transform(chunk, encoding, cb) {
// if this is called, _flush isn't called
if (this.err) return cb(this.err);
if (this.maxSize === Infinity) return cb(null, chunk);
this.byteCount += chunk.length;
if (this.byteCount > this.maxSize) {
const remainingBytes = this.maxSize - this.byteCount;
const lastChunk = chunk.slice(0, remainingBytes);
this.err = new OverflowError(`Stream exceeded specified max of ${ this.maxSize } bytes.`);
// flush remaining chunk and wait until next
// _transform or _flush call to emit error
return cb(null, lastChunk);
}
cb(null, chunk);
}
// if error detected on last call to _transform
// flush will be called with the error
_flush(cb) {
cb(this.err);
}
}
MeterSream.OverflowError = OverflowError;
exports.default = MeterSream;
+56
View File
@@ -0,0 +1,56 @@
{
"name": "meterstream",
"version": "1.0.1",
"description": "",
"main": "./lib/index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "npm run test:fast",
"build": "npm run clean && babel ./src --out-dir ./lib --copy-files",
"clean": "rimraf ./lib",
"lint": "eslint src/ test/",
"pretest": "npm run lint",
"test:fast": "babel-tape-runner test/*.test.js",
"test:watch": "nodemon --exec npm -- run --silent test:fast || true",
"semantic-release": "git push && npm test && semantic-release pre && npm run build && npm publish && semantic-release post"
},
"repository": {
"type": "git",
"url": "git+https://github.com/blockai/meterstream.git"
},
"keywords": [],
"author": "Oli Lalonde <olalonde@gmail.com> (https://syskall.com/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/blockai/meterstream/issues"
},
"homepage": "https://github.com/blockai/meterstream#readme",
"engines": {
"node": ">=6"
},
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-preset-blockai": "^1.0.0",
"babel-tape-runner": "^2.0.1",
"blue-tape": "^1.0.0",
"concat-stream": "^1.5.2",
"cz-conventional-changelog": "^1.2.0",
"eslint-config-blockai": "^1.0.1",
"nodemon": "^1.10.2",
"rimraf": "^2.5.4",
"semantic-release": "^4.3.5"
},
"release": {
"debug": false,
"verifyConditions": {
"path": "./node_modules/semantic-release/dist/lib/plugin-noop.js"
}
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
}
}