@dragon708/docmind-markdown 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@tokenizer/token/README.md +19 -0
- package/node_modules/@tokenizer/token/index.d.ts +30 -0
- package/node_modules/@tokenizer/token/package.json +33 -0
- package/node_modules/ieee754/LICENSE +11 -0
- package/node_modules/ieee754/README.md +51 -0
- package/node_modules/ieee754/index.d.ts +10 -0
- package/node_modules/ieee754/index.js +85 -0
- package/node_modules/ieee754/package.json +52 -0
- package/node_modules/peek-readable/LICENSE +21 -0
- package/node_modules/peek-readable/README.md +93 -0
- package/node_modules/peek-readable/lib/Deferred.d.ts +6 -0
- package/node_modules/peek-readable/lib/Deferred.js +14 -0
- package/node_modules/peek-readable/lib/EndOfFileStream.d.ts +7 -0
- package/node_modules/peek-readable/lib/EndOfFileStream.js +13 -0
- package/node_modules/peek-readable/lib/StreamReader.d.ts +47 -0
- package/node_modules/peek-readable/lib/StreamReader.js +134 -0
- package/node_modules/peek-readable/lib/index.d.ts +2 -0
- package/node_modules/peek-readable/lib/index.js +7 -0
- package/node_modules/peek-readable/package.json +87 -0
- package/package.json +4 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@tokenizer/token)
|
|
2
|
+
[](https://npmcharts.com/compare/@tokenizer/token?interval=30)
|
|
3
|
+
|
|
4
|
+
# @tokenizer/token
|
|
5
|
+
|
|
6
|
+
TypeScript definition of an [strtok3](https://github.com/Borewit/strtok3) token.
|
|
7
|
+
|
|
8
|
+
## Licence
|
|
9
|
+
|
|
10
|
+
(The MIT License)
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2020 Borewit
|
|
13
|
+
|
|
14
|
+
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:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
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.
|
|
19
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only token
|
|
3
|
+
* See https://github.com/Borewit/strtok3 for more information
|
|
4
|
+
*/
|
|
5
|
+
export interface IGetToken<Value, Array extends Uint8Array = Uint8Array> {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Length of encoded token in bytes
|
|
9
|
+
*/
|
|
10
|
+
len: number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Decode value from buffer at offset
|
|
14
|
+
* @param array - Uint8Array to read the decoded value from
|
|
15
|
+
* @param offset - Decode offset
|
|
16
|
+
* @return decoded value
|
|
17
|
+
*/
|
|
18
|
+
get(array: Array, offset: number): Value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IToken<Value, Array extends Uint8Array = Uint8Array> extends IGetToken<Value, Array> {
|
|
22
|
+
/**
|
|
23
|
+
* Encode value to buffer
|
|
24
|
+
* @param array - Uint8Array to write the encoded value to
|
|
25
|
+
* @param offset - Buffer write offset
|
|
26
|
+
* @param value - Value to decode of type T
|
|
27
|
+
* @return offset plus number of bytes written
|
|
28
|
+
*/
|
|
29
|
+
put(array: Array, offset: number, value: Value): number
|
|
30
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tokenizer/token",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "TypeScript definition for strtok3 token",
|
|
5
|
+
"main": "",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"token",
|
|
12
|
+
"interface",
|
|
13
|
+
"tokenizer",
|
|
14
|
+
"TypeScript"
|
|
15
|
+
],
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Borewit",
|
|
18
|
+
"url": "https://github.com/Borewit"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/Borewit/tokenizer-token.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Borewit/tokenizer-token/issues"
|
|
27
|
+
},
|
|
28
|
+
"typeScriptVersion": "3.0",
|
|
29
|
+
"dependencies": {},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^13.1.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Copyright 2008 Fair Oaks Labs, Inc.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# ieee754 [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
|
|
2
|
+
|
|
3
|
+
[travis-image]: https://img.shields.io/travis/feross/ieee754/master.svg
|
|
4
|
+
[travis-url]: https://travis-ci.org/feross/ieee754
|
|
5
|
+
[npm-image]: https://img.shields.io/npm/v/ieee754.svg
|
|
6
|
+
[npm-url]: https://npmjs.org/package/ieee754
|
|
7
|
+
[downloads-image]: https://img.shields.io/npm/dm/ieee754.svg
|
|
8
|
+
[downloads-url]: https://npmjs.org/package/ieee754
|
|
9
|
+
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
|
|
10
|
+
[standard-url]: https://standardjs.com
|
|
11
|
+
|
|
12
|
+
[![saucelabs][saucelabs-image]][saucelabs-url]
|
|
13
|
+
|
|
14
|
+
[saucelabs-image]: https://saucelabs.com/browser-matrix/ieee754.svg
|
|
15
|
+
[saucelabs-url]: https://saucelabs.com/u/ieee754
|
|
16
|
+
|
|
17
|
+
### Read/write IEEE754 floating point numbers from/to a Buffer or array-like object.
|
|
18
|
+
|
|
19
|
+
## install
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm install ieee754
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## methods
|
|
26
|
+
|
|
27
|
+
`var ieee754 = require('ieee754')`
|
|
28
|
+
|
|
29
|
+
The `ieee754` object has the following functions:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
ieee754.read = function (buffer, offset, isLE, mLen, nBytes)
|
|
33
|
+
ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The arguments mean the following:
|
|
37
|
+
|
|
38
|
+
- buffer = the buffer
|
|
39
|
+
- offset = offset into the buffer
|
|
40
|
+
- value = value to set (only for `write`)
|
|
41
|
+
- isLe = is little endian?
|
|
42
|
+
- mLen = mantissa length
|
|
43
|
+
- nBytes = number of bytes
|
|
44
|
+
|
|
45
|
+
## what is ieee754?
|
|
46
|
+
|
|
47
|
+
The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point computation. [Read more](http://en.wikipedia.org/wiki/IEEE_floating_point).
|
|
48
|
+
|
|
49
|
+
## license
|
|
50
|
+
|
|
51
|
+
BSD 3 Clause. Copyright (c) 2008, Fair Oaks Labs, Inc.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare namespace ieee754 {
|
|
2
|
+
export function read(
|
|
3
|
+
buffer: Uint8Array, offset: number, isLE: boolean, mLen: number,
|
|
4
|
+
nBytes: number): number;
|
|
5
|
+
export function write(
|
|
6
|
+
buffer: Uint8Array, value: number, offset: number, isLE: boolean,
|
|
7
|
+
mLen: number, nBytes: number): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export = ieee754;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
2
|
+
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
|
3
|
+
var e, m
|
|
4
|
+
var eLen = (nBytes * 8) - mLen - 1
|
|
5
|
+
var eMax = (1 << eLen) - 1
|
|
6
|
+
var eBias = eMax >> 1
|
|
7
|
+
var nBits = -7
|
|
8
|
+
var i = isLE ? (nBytes - 1) : 0
|
|
9
|
+
var d = isLE ? -1 : 1
|
|
10
|
+
var s = buffer[offset + i]
|
|
11
|
+
|
|
12
|
+
i += d
|
|
13
|
+
|
|
14
|
+
e = s & ((1 << (-nBits)) - 1)
|
|
15
|
+
s >>= (-nBits)
|
|
16
|
+
nBits += eLen
|
|
17
|
+
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
18
|
+
|
|
19
|
+
m = e & ((1 << (-nBits)) - 1)
|
|
20
|
+
e >>= (-nBits)
|
|
21
|
+
nBits += mLen
|
|
22
|
+
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
23
|
+
|
|
24
|
+
if (e === 0) {
|
|
25
|
+
e = 1 - eBias
|
|
26
|
+
} else if (e === eMax) {
|
|
27
|
+
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
28
|
+
} else {
|
|
29
|
+
m = m + Math.pow(2, mLen)
|
|
30
|
+
e = e - eBias
|
|
31
|
+
}
|
|
32
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
36
|
+
var e, m, c
|
|
37
|
+
var eLen = (nBytes * 8) - mLen - 1
|
|
38
|
+
var eMax = (1 << eLen) - 1
|
|
39
|
+
var eBias = eMax >> 1
|
|
40
|
+
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
|
41
|
+
var i = isLE ? 0 : (nBytes - 1)
|
|
42
|
+
var d = isLE ? 1 : -1
|
|
43
|
+
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
|
44
|
+
|
|
45
|
+
value = Math.abs(value)
|
|
46
|
+
|
|
47
|
+
if (isNaN(value) || value === Infinity) {
|
|
48
|
+
m = isNaN(value) ? 1 : 0
|
|
49
|
+
e = eMax
|
|
50
|
+
} else {
|
|
51
|
+
e = Math.floor(Math.log(value) / Math.LN2)
|
|
52
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
53
|
+
e--
|
|
54
|
+
c *= 2
|
|
55
|
+
}
|
|
56
|
+
if (e + eBias >= 1) {
|
|
57
|
+
value += rt / c
|
|
58
|
+
} else {
|
|
59
|
+
value += rt * Math.pow(2, 1 - eBias)
|
|
60
|
+
}
|
|
61
|
+
if (value * c >= 2) {
|
|
62
|
+
e++
|
|
63
|
+
c /= 2
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (e + eBias >= eMax) {
|
|
67
|
+
m = 0
|
|
68
|
+
e = eMax
|
|
69
|
+
} else if (e + eBias >= 1) {
|
|
70
|
+
m = ((value * c) - 1) * Math.pow(2, mLen)
|
|
71
|
+
e = e + eBias
|
|
72
|
+
} else {
|
|
73
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
|
74
|
+
e = 0
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
79
|
+
|
|
80
|
+
e = (e << mLen) | m
|
|
81
|
+
eLen += mLen
|
|
82
|
+
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
83
|
+
|
|
84
|
+
buffer[offset + i - d] |= s * 128
|
|
85
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ieee754",
|
|
3
|
+
"description": "Read/write IEEE754 floating point numbers from/to a Buffer or array-like object",
|
|
4
|
+
"version": "1.2.1",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Feross Aboukhadijeh",
|
|
7
|
+
"email": "feross@feross.org",
|
|
8
|
+
"url": "https://feross.org"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
"Romain Beauxis <toots@rastageeks.org>"
|
|
12
|
+
],
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"airtap": "^3.0.0",
|
|
15
|
+
"standard": "*",
|
|
16
|
+
"tape": "^5.0.1"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"IEEE 754",
|
|
20
|
+
"buffer",
|
|
21
|
+
"convert",
|
|
22
|
+
"floating point",
|
|
23
|
+
"ieee754"
|
|
24
|
+
],
|
|
25
|
+
"license": "BSD-3-Clause",
|
|
26
|
+
"main": "index.js",
|
|
27
|
+
"types": "index.d.ts",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git://github.com/feross/ieee754.git"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "standard && npm run test-node && npm run test-browser",
|
|
34
|
+
"test-browser": "airtap -- test/*.js",
|
|
35
|
+
"test-browser-local": "airtap --local -- test/*.js",
|
|
36
|
+
"test-node": "tape test/*.js"
|
|
37
|
+
},
|
|
38
|
+
"funding": [
|
|
39
|
+
{
|
|
40
|
+
"type": "github",
|
|
41
|
+
"url": "https://github.com/sponsors/feross"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"type": "patreon",
|
|
45
|
+
"url": "https://www.patreon.com/feross"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"type": "consulting",
|
|
49
|
+
"url": "https://feross.org/support"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2010-2017 Borewit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+

|
|
2
|
+
[](https://npmjs.org/package/peek-readable)
|
|
3
|
+
[](https://npmcharts.com/compare/peek-readable?start=600&interval=30)
|
|
4
|
+
[](https://coveralls.io/github/Borewit/peek-readable?branch=master)
|
|
5
|
+
[](https://www.codacy.com/gh/Borewit/peek-readable/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Borewit/peek-readable&utm_campaign=Badge_Grade)
|
|
6
|
+
[](https://lgtm.com/projects/g/Borewit/peek-readable/alerts/)
|
|
7
|
+
[](https://lgtm.com/projects/g/Borewit/peek-readable/context:javascript)
|
|
8
|
+
[](https://snyk.io/test/github/Borewit/peek-readable?targetFile=package.json)
|
|
9
|
+
|
|
10
|
+
# peek-readable
|
|
11
|
+
|
|
12
|
+
A promise based asynchronous stream reader, which makes reading from a stream easy.
|
|
13
|
+
|
|
14
|
+
Allows to read and peek from a [Readable Stream](https://nodejs.org/api/stream.html#stream_readable_streams)
|
|
15
|
+
|
|
16
|
+
Note that [peek-readable](https://github.com/Borewit/peek-readable) was formally released as [then-read-stream](https://github.com/Borewit/peek-readable).
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
```shell script
|
|
23
|
+
npm install --save peek-readable
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The `peek-readable` contains one class: `StreamReader`, which reads from a [stream.Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable).
|
|
27
|
+
|
|
28
|
+
### Compatibility
|
|
29
|
+
|
|
30
|
+
NPM module is compliant with [ECMAScript 2018 (ES9)](https://en.wikipedia.org/wiki/ECMAScript#9th_Edition_%E2%80%93_ECMAScript_2018).
|
|
31
|
+
|
|
32
|
+
## Examples
|
|
33
|
+
|
|
34
|
+
In the following example we read the first 16 bytes from a stream and store them in our buffer.
|
|
35
|
+
Source code of examples can be found [here](test/examples.ts).
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const fs = require('fs');
|
|
39
|
+
const { StreamReader } = require('peek-readable');
|
|
40
|
+
|
|
41
|
+
(async () => {
|
|
42
|
+
const readable = fs.createReadStream('JPEG_example_JPG_RIP_001.jpg');
|
|
43
|
+
const streamReader = new StreamReader(readable);
|
|
44
|
+
const uint8Array = new Uint8Array(16);
|
|
45
|
+
const bytesRead = await streamReader.read(uint8Array, 0, 16);;
|
|
46
|
+
// buffer contains 16 bytes, if the end-of-stream has not been reached
|
|
47
|
+
})();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
End-of-stream detection:
|
|
51
|
+
```js
|
|
52
|
+
(async () => {
|
|
53
|
+
|
|
54
|
+
const fileReadStream = fs.createReadStream('JPEG_example_JPG_RIP_001.jpg');
|
|
55
|
+
const streamReader = new StreamReader(fileReadStream);
|
|
56
|
+
const buffer = Buffer.alloc(16); // or use: new Uint8Array(16);
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
await streamReader.read(buffer, 0, 16);
|
|
60
|
+
// buffer contains 16 bytes, if the end-of-stream has not been reached
|
|
61
|
+
} catch(error) {
|
|
62
|
+
if (error instanceof EndOfStreamError) {
|
|
63
|
+
console.log('End-of-stream reached');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
With peek you can read ahead:
|
|
70
|
+
```js
|
|
71
|
+
const fs = require('fs');
|
|
72
|
+
const { StreamReader } = require('peek-readable');
|
|
73
|
+
|
|
74
|
+
const fileReadStream = fs.createReadStream('JPEG_example_JPG_RIP_001.jpg');
|
|
75
|
+
const streamReader = new StreamReader(fileReadStream);
|
|
76
|
+
const buffer = Buffer.alloc(20);
|
|
77
|
+
|
|
78
|
+
(async () => {
|
|
79
|
+
let bytesRead = await streamReader.peek(buffer, 0, 3);
|
|
80
|
+
if (bytesRead === 3 && buffer[0] === 0xFF && buffer[1] === 0xD8 && buffer[2] === 0xFF) {
|
|
81
|
+
console.log('This is a JPEG file');
|
|
82
|
+
} else {
|
|
83
|
+
throw Error('Expected a JPEG file');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
bytesRead = await streamReader.read(buffer, 0, 20); // Read JPEG header
|
|
87
|
+
if (bytesRead === 20) {
|
|
88
|
+
console.log('Got the JPEG header');
|
|
89
|
+
} else {
|
|
90
|
+
throw Error('Failed to read JPEG header');
|
|
91
|
+
}
|
|
92
|
+
})();
|
|
93
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Deferred = void 0;
|
|
4
|
+
class Deferred {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.resolve = () => null;
|
|
7
|
+
this.reject = () => null;
|
|
8
|
+
this.promise = new Promise((resolve, reject) => {
|
|
9
|
+
this.reject = reject;
|
|
10
|
+
this.resolve = resolve;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Deferred = Deferred;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EndOfStreamError = exports.defaultMessages = void 0;
|
|
4
|
+
exports.defaultMessages = 'End-Of-Stream';
|
|
5
|
+
/**
|
|
6
|
+
* Thrown on read operation of the end of file or stream has been reached
|
|
7
|
+
*/
|
|
8
|
+
class EndOfStreamError extends Error {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(exports.defaultMessages);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.EndOfStreamError = EndOfStreamError;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
export { EndOfStreamError } from './EndOfFileStream';
|
|
4
|
+
export declare class StreamReader {
|
|
5
|
+
private s;
|
|
6
|
+
/**
|
|
7
|
+
* Deferred used for postponed read request (as not data is yet available to read)
|
|
8
|
+
*/
|
|
9
|
+
private deferred;
|
|
10
|
+
private endOfStream;
|
|
11
|
+
/**
|
|
12
|
+
* Store peeked data
|
|
13
|
+
* @type {Array}
|
|
14
|
+
*/
|
|
15
|
+
private peekQueue;
|
|
16
|
+
constructor(s: Readable);
|
|
17
|
+
/**
|
|
18
|
+
* Read ahead (peek) from stream. Subsequent read or peeks will return the same data
|
|
19
|
+
* @param uint8Array - Uint8Array (or Buffer) to store data read from stream in
|
|
20
|
+
* @param offset - Offset target
|
|
21
|
+
* @param length - Number of bytes to read
|
|
22
|
+
* @returns Number of bytes peeked
|
|
23
|
+
*/
|
|
24
|
+
peek(uint8Array: Uint8Array, offset: number, length: number): Promise<number>;
|
|
25
|
+
/**
|
|
26
|
+
* Read chunk from stream
|
|
27
|
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
|
28
|
+
* @param offset - Offset target
|
|
29
|
+
* @param length - Number of bytes to read
|
|
30
|
+
* @returns Number of bytes read
|
|
31
|
+
*/
|
|
32
|
+
read(buffer: Uint8Array, offset: number, length: number): Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Read chunk from stream
|
|
35
|
+
* @param buffer Target Uint8Array (or Buffer) to store data read from stream in
|
|
36
|
+
* @param offset Offset target
|
|
37
|
+
* @param length Number of bytes to read
|
|
38
|
+
* @returns Number of bytes read
|
|
39
|
+
*/
|
|
40
|
+
private readFromStream;
|
|
41
|
+
/**
|
|
42
|
+
* Process deferred read request
|
|
43
|
+
* @param request Deferred read request
|
|
44
|
+
*/
|
|
45
|
+
private readDeferred;
|
|
46
|
+
private reject;
|
|
47
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamReader = exports.EndOfStreamError = void 0;
|
|
4
|
+
const EndOfFileStream_1 = require("./EndOfFileStream");
|
|
5
|
+
const Deferred_1 = require("./Deferred");
|
|
6
|
+
var EndOfFileStream_2 = require("./EndOfFileStream");
|
|
7
|
+
Object.defineProperty(exports, "EndOfStreamError", { enumerable: true, get: function () { return EndOfFileStream_2.EndOfStreamError; } });
|
|
8
|
+
const maxStreamReadSize = 1 * 1024 * 1024; // Maximum request length on read-stream operation
|
|
9
|
+
class StreamReader {
|
|
10
|
+
constructor(s) {
|
|
11
|
+
this.s = s;
|
|
12
|
+
/**
|
|
13
|
+
* Deferred used for postponed read request (as not data is yet available to read)
|
|
14
|
+
*/
|
|
15
|
+
this.deferred = null;
|
|
16
|
+
this.endOfStream = false;
|
|
17
|
+
/**
|
|
18
|
+
* Store peeked data
|
|
19
|
+
* @type {Array}
|
|
20
|
+
*/
|
|
21
|
+
this.peekQueue = [];
|
|
22
|
+
if (!s.read || !s.once) {
|
|
23
|
+
throw new Error('Expected an instance of stream.Readable');
|
|
24
|
+
}
|
|
25
|
+
this.s.once('end', () => this.reject(new EndOfFileStream_1.EndOfStreamError()));
|
|
26
|
+
this.s.once('error', err => this.reject(err));
|
|
27
|
+
this.s.once('close', () => this.reject(new Error('Stream closed')));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read ahead (peek) from stream. Subsequent read or peeks will return the same data
|
|
31
|
+
* @param uint8Array - Uint8Array (or Buffer) to store data read from stream in
|
|
32
|
+
* @param offset - Offset target
|
|
33
|
+
* @param length - Number of bytes to read
|
|
34
|
+
* @returns Number of bytes peeked
|
|
35
|
+
*/
|
|
36
|
+
async peek(uint8Array, offset, length) {
|
|
37
|
+
const bytesRead = await this.read(uint8Array, offset, length);
|
|
38
|
+
this.peekQueue.push(uint8Array.subarray(offset, offset + bytesRead)); // Put read data back to peek buffer
|
|
39
|
+
return bytesRead;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Read chunk from stream
|
|
43
|
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
|
44
|
+
* @param offset - Offset target
|
|
45
|
+
* @param length - Number of bytes to read
|
|
46
|
+
* @returns Number of bytes read
|
|
47
|
+
*/
|
|
48
|
+
async read(buffer, offset, length) {
|
|
49
|
+
if (length === 0) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
if (this.peekQueue.length === 0 && this.endOfStream) {
|
|
53
|
+
throw new EndOfFileStream_1.EndOfStreamError();
|
|
54
|
+
}
|
|
55
|
+
let remaining = length;
|
|
56
|
+
let bytesRead = 0;
|
|
57
|
+
// consume peeked data first
|
|
58
|
+
while (this.peekQueue.length > 0 && remaining > 0) {
|
|
59
|
+
const peekData = this.peekQueue.pop(); // Front of queue
|
|
60
|
+
if (!peekData)
|
|
61
|
+
throw new Error('peekData should be defined');
|
|
62
|
+
const lenCopy = Math.min(peekData.length, remaining);
|
|
63
|
+
buffer.set(peekData.subarray(0, lenCopy), offset + bytesRead);
|
|
64
|
+
bytesRead += lenCopy;
|
|
65
|
+
remaining -= lenCopy;
|
|
66
|
+
if (lenCopy < peekData.length) {
|
|
67
|
+
// remainder back to queue
|
|
68
|
+
this.peekQueue.push(peekData.subarray(lenCopy));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// continue reading from stream if required
|
|
72
|
+
while (remaining > 0 && !this.endOfStream) {
|
|
73
|
+
const reqLen = Math.min(remaining, maxStreamReadSize);
|
|
74
|
+
const chunkLen = await this.readFromStream(buffer, offset + bytesRead, reqLen);
|
|
75
|
+
bytesRead += chunkLen;
|
|
76
|
+
if (chunkLen < reqLen)
|
|
77
|
+
break;
|
|
78
|
+
remaining -= chunkLen;
|
|
79
|
+
}
|
|
80
|
+
return bytesRead;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Read chunk from stream
|
|
84
|
+
* @param buffer Target Uint8Array (or Buffer) to store data read from stream in
|
|
85
|
+
* @param offset Offset target
|
|
86
|
+
* @param length Number of bytes to read
|
|
87
|
+
* @returns Number of bytes read
|
|
88
|
+
*/
|
|
89
|
+
async readFromStream(buffer, offset, length) {
|
|
90
|
+
const readBuffer = this.s.read(length);
|
|
91
|
+
if (readBuffer) {
|
|
92
|
+
buffer.set(readBuffer, offset);
|
|
93
|
+
return readBuffer.length;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const request = {
|
|
97
|
+
buffer,
|
|
98
|
+
offset,
|
|
99
|
+
length,
|
|
100
|
+
deferred: new Deferred_1.Deferred()
|
|
101
|
+
};
|
|
102
|
+
this.deferred = request.deferred;
|
|
103
|
+
this.s.once('readable', () => {
|
|
104
|
+
this.readDeferred(request);
|
|
105
|
+
});
|
|
106
|
+
return request.deferred.promise;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Process deferred read request
|
|
111
|
+
* @param request Deferred read request
|
|
112
|
+
*/
|
|
113
|
+
readDeferred(request) {
|
|
114
|
+
const readBuffer = this.s.read(request.length);
|
|
115
|
+
if (readBuffer) {
|
|
116
|
+
request.buffer.set(readBuffer, request.offset);
|
|
117
|
+
request.deferred.resolve(readBuffer.length);
|
|
118
|
+
this.deferred = null;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.s.once('readable', () => {
|
|
122
|
+
this.readDeferred(request);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
reject(err) {
|
|
127
|
+
this.endOfStream = true;
|
|
128
|
+
if (this.deferred) {
|
|
129
|
+
this.deferred.reject(err);
|
|
130
|
+
this.deferred = null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.StreamReader = StreamReader;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamReader = exports.EndOfStreamError = void 0;
|
|
4
|
+
var EndOfFileStream_1 = require("./EndOfFileStream");
|
|
5
|
+
Object.defineProperty(exports, "EndOfStreamError", { enumerable: true, get: function () { return EndOfFileStream_1.EndOfStreamError; } });
|
|
6
|
+
var StreamReader_1 = require("./StreamReader");
|
|
7
|
+
Object.defineProperty(exports, "StreamReader", { enumerable: true, get: function () { return StreamReader_1.StreamReader; } });
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "peek-readable",
|
|
3
|
+
"version": "4.1.0",
|
|
4
|
+
"description": "Read and peek from a readable stream",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Borewit",
|
|
7
|
+
"url": "https://github.com/Borewit"
|
|
8
|
+
},
|
|
9
|
+
"funding": {
|
|
10
|
+
"type": "github",
|
|
11
|
+
"url": "https://github.com/sponsors/Borewit"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"clean": "del-cli lib/**/*.js lib/**/*.js.map lib/**/*.d.ts test/**/*.js test/**/*.js.map coverage .nyc_output",
|
|
15
|
+
"build": "npm run clean && npm run compile",
|
|
16
|
+
"compile-src": "tsc -p lib",
|
|
17
|
+
"compile-test": "tsc -p test",
|
|
18
|
+
"compile": "npm run compile-src && yarn run compile-test",
|
|
19
|
+
"eslint": "eslint lib test --ext .ts --ignore-pattern *.d.ts",
|
|
20
|
+
"lint-md": "remark -u preset-lint-recommended .",
|
|
21
|
+
"lint": "npm run lint-md && npm run eslint",
|
|
22
|
+
"test": "mocha --require ts-node/register --require source-map-support/register --full-trace test/*.ts",
|
|
23
|
+
"test-coverage": "nyc npm run test",
|
|
24
|
+
"send-coveralls": "nyc report --reporter=text-lcov | coveralls",
|
|
25
|
+
"start": "npm run compile && npm run lint && npm run cover-test"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=8"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/Borewit/peek-readable"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"main": "lib/index.js",
|
|
36
|
+
"types": "lib/index.d.ts",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/Borewit/peek-readable/issues"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"lib/**/*.js",
|
|
42
|
+
"lib/**/*.d.ts"
|
|
43
|
+
],
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/chai": "^4.3.0",
|
|
46
|
+
"@types/mocha": "^9.1.0",
|
|
47
|
+
"@types/node": "^17.0.0",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
49
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
50
|
+
"add": "^2.0.6",
|
|
51
|
+
"chai": "^4.3.6",
|
|
52
|
+
"coveralls": "^3.1.1",
|
|
53
|
+
"del-cli": "^4.0.1",
|
|
54
|
+
"eslint": "^7.32.0",
|
|
55
|
+
"eslint-config-prettier": "^8.3.0",
|
|
56
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
57
|
+
"eslint-plugin-import": "^2.25.4",
|
|
58
|
+
"eslint-plugin-jsdoc": "^37.7.1",
|
|
59
|
+
"eslint-plugin-node": "^11.1.0",
|
|
60
|
+
"eslint-plugin-unicorn": "^40.1.0",
|
|
61
|
+
"mocha": "^9.2.0",
|
|
62
|
+
"nyc": "^15.1.0",
|
|
63
|
+
"remark-cli": "^10.0.1",
|
|
64
|
+
"remark-preset-lint-recommended": "^6.1.2",
|
|
65
|
+
"ts-node": "^10.4.0",
|
|
66
|
+
"typescript": "^4.5.5"
|
|
67
|
+
},
|
|
68
|
+
"keywords": [
|
|
69
|
+
"readable",
|
|
70
|
+
"buffer",
|
|
71
|
+
"stream",
|
|
72
|
+
"read"
|
|
73
|
+
],
|
|
74
|
+
"nyc": {
|
|
75
|
+
"check-coverage": true,
|
|
76
|
+
"extension": [
|
|
77
|
+
".ts"
|
|
78
|
+
],
|
|
79
|
+
"sourceMap": true,
|
|
80
|
+
"instrument": true,
|
|
81
|
+
"reporter": [
|
|
82
|
+
"lcov",
|
|
83
|
+
"text"
|
|
84
|
+
],
|
|
85
|
+
"report-dir": "coverage"
|
|
86
|
+
}
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dragon708/docmind-markdown",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "StructuredDocumentResult → Markdown and LLM-oriented plain text for DocMind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"bundledDependencies": [
|
|
47
47
|
"@cognipeer/to-markdown",
|
|
48
48
|
"@opendocsg/pdf2md",
|
|
49
|
+
"@tokenizer/token",
|
|
49
50
|
"adm-zip",
|
|
50
51
|
"adler-32",
|
|
51
52
|
"boolbase",
|
|
@@ -65,6 +66,7 @@
|
|
|
65
66
|
"enumify",
|
|
66
67
|
"file-type",
|
|
67
68
|
"htmlparser2",
|
|
69
|
+
"ieee754",
|
|
68
70
|
"iconv-lite",
|
|
69
71
|
"image-size",
|
|
70
72
|
"mime-db",
|
|
@@ -73,6 +75,7 @@
|
|
|
73
75
|
"music-metadata",
|
|
74
76
|
"nth-check",
|
|
75
77
|
"papaparse",
|
|
78
|
+
"peek-readable",
|
|
76
79
|
"parse5",
|
|
77
80
|
"parse5-htmlparser2-tree-adapter",
|
|
78
81
|
"parse5-parser-stream",
|