Browse Source

Initial commit

master
Sven Slootweg 1 month ago
commit
3e84ede3b1
5 changed files with 1370 additions and 0 deletions
  1. +3
    -0
      .eslintrc
  2. +1
    -0
      .gitignore
  3. +45
    -0
      index.js
  4. +24
    -0
      package.json
  5. +1297
    -0
      yarn.lock

+ 3
- 0
.eslintrc View File

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

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
node_modules

+ 45
- 0
index.js View File

@ -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;
})
]);
};

+ 24
- 0
package.json View File

@ -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"
}
}

+ 1297
- 0
yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save