Project files

This commit is contained in:
2023-11-09 18:47:11 +01:00
parent 695abe054b
commit c415135aae
8554 changed files with 858111 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
sudo: false
language: node_js
node_js:
- "6"
- "8"
- "10"
- "11.1"
- "12"
script:
- npm run lint
- npm test
- npm run coverage

View File

@@ -0,0 +1,44 @@
# Handle Thing
[![Build Status](https://travis-ci.org/spdy-http2/handle-thing.svg?branch=master)](http://travis-ci.org/spdy-http2/handle-thing)
[![NPM version](https://badge.fury.io/js/handle-thing.svg)](http://badge.fury.io/js/handle-thing)
[![dependencies Status](https://david-dm.org/spdy-http2/handle-thing/status.svg?style=flat-square)](https://david-dm.org/spdy-http2/handle-thing)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)
[![Waffle](https://img.shields.io/badge/track-waffle-blue.svg?style=flat-square)](https://waffle.io/spdy-http2/node-spdy)
> Wrap Streams2 instance into a HandleWrap. The right thing when you need it
## Usage
### Examples
`soon™`
### API
`soon™`
## LICENSE
This software is licensed under the MIT License.
Copyright Fedor Indutny, 2015.
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 File

@@ -0,0 +1,38 @@
{
"name": "handle-thing",
"version": "2.0.1",
"description": "Wrap Streams2 instance into a HandleWrap",
"main": "lib/handle.js",
"scripts": {
"lint": "standard",
"test": "mocha --reporter=spec test/*-test.js",
"coverage": "istanbul cover node_modules/.bin/_mocha -- --reporter=spec test/**/*-test.js"
},
"pre-commit": [
"lint",
"test"
],
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/indutny/handle-thing.git"
},
"keywords": [
"handle",
"net",
"streams2"
],
"author": "Fedor Indutny <fedor@indutny.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/spdy-http2/handle-thing/issues"
},
"homepage": "https://github.com/spdy-http2/handle-thing#readme",
"devDependencies": {
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"pre-commit": "^1.2.2",
"readable-stream": "^3.0.6",
"standard": "^12.0.1",
"stream-pair": "^1.0.3"
}
}

View File

@@ -0,0 +1,110 @@
/* eslint-env mocha */
var assert = require('assert')
var net = require('net')
var streamPair = require('stream-pair')
var thing = require('../')
describe('Handle Thing', function () {
var handle
var pair
var socket;
[ 'normal', 'lazy' ].forEach(function (mode) {
describe(mode, function () {
beforeEach(function () {
pair = streamPair.create()
handle = thing.create(mode === 'normal' ? pair.other : null)
socket = new net.Socket({
handle: handle,
readable: true,
writable: true
})
if (mode === 'lazy') {
setTimeout(function () {
handle.setStream(pair.other)
}, 50)
}
})
afterEach(function () {
assert(handle._stream)
})
it('should write data to Socket', function (done) {
pair.write('hello')
pair.write(' world')
pair.end('... ok')
var chunks = ''
socket.on('data', function (chunk) {
chunks += chunk
})
socket.on('end', function () {
assert.strictEqual(chunks, 'hello world... ok')
// allowHalfOpen is `false`, so the `end` should be followed by `close`
socket.once('close', function () {
done()
})
})
})
it('should read data from Socket', function (done) {
socket.write('hello')
socket.write(' world')
socket.end('... ok')
var chunks = ''
pair.on('data', function (chunk) {
chunks += chunk
})
pair.on('end', function () {
assert.strictEqual(chunks, 'hello world... ok')
done()
})
})
it('should invoke `close` callback', function (done) {
handle._options.close = function (callback) {
done()
process.nextTick(callback)
}
pair.end('hello')
socket.resume()
})
it('should kill pending requests', function (done) {
handle._options.close = function () {
setTimeout(done, 75)
}
socket.write('hello')
socket.destroy()
})
if (mode === 'normal') {
it('should invoke `getPeerName` callback', function () {
handle._options.getPeerName = function () {
return { address: 'ohai' }
}
assert.strictEqual(socket.remoteAddress, 'ohai')
})
it('should emit ECONNRESET at `close` event', function (done) {
pair.other.emit('close')
socket.on('error', function (err) {
assert(/ECONNRESET/.test(err.message))
done()
})
})
}
})
})
})