Initial commit

master
Sven Slootweg 4 years ago
commit 3e84ede3b1

@ -0,0 +1,3 @@
{
"extends": "@joepie91/eslint-config"
}

1
.gitignore vendored

@ -0,0 +1 @@
node_modules

@ -0,0 +1,45 @@
"use strict";
const { StringDecoder } = require("string_decoder");
const pipe = require("@promistream/pipe");
const map = require("@promistream/map");
const buffer = require("@promistream/buffer");
const lastWill = require("@promistream/last-will");
const { validateArguments } = require("@validatem/core");
const required = require("@validatem/required");
const ValidationError = require("@validatem/error");
// FIXME: Move into separate @validatem/* package
function isValidTextEncoding(encoding) {
if (!Buffer.isEncoding(encoding)) {
throw new ValidationError(`Must be a valid Buffer text encoding`);
}
}
module.exports = function decodeString(_encoding) {
let [ encoding ] = validateArguments(arguments, {
encoding: [ required, isValidTextEncoding ]
});
let decoder = new StringDecoder(encoding);
return pipe([
map((inputBuffer) => {
let decoded = decoder.write(inputBuffer);
return (decoded.length > 0)
? [ decoded ]
: [];
}),
buffer(),
lastWill(() => {
let lastChunk = decoder.end();
return (lastChunk.length > 0)
? lastChunk
: lastWill.NoValue;
})
]);
};

@ -0,0 +1,24 @@
{
"name": "@promistream/decode-string",
"version": "0.1.0",
"main": "index.js",
"keywords": [
"promistream"
],
"repository": "http://git.cryto.net/promistream/decode-string.git",
"author": "Sven Slootweg <admin@cryto.net>",
"license": "WTFPL OR CC0-1.0",
"devDependencies": {
"@joepie91/eslint-config": "^1.1.0",
"eslint": "^6.8.0"
},
"dependencies": {
"@promistream/buffer": "^0.1.2",
"@promistream/last-will": "^0.1.0",
"@promistream/map": "^0.1.1",
"@promistream/pipe": "^0.1.4",
"@validatem/core": "^0.3.15",
"@validatem/error": "^1.1.0",
"@validatem/required": "^0.1.1"
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save