rar-stream 1.3.6 → 2.0.1

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.
Files changed (39) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/README.md +50 -40
  3. package/example/package-lock.json +1712 -7092
  4. package/example/package.json +2 -1
  5. package/example/webtorrent.js +3 -6
  6. package/package.json +7 -8
  7. package/src/index.js +1 -3
  8. package/src/inner-file-stream.js +5 -5
  9. package/src/inner-file.js +9 -10
  10. package/src/local-file-media.js +7 -7
  11. package/src/parsing/__mocks__/mock-file-media.js +6 -6
  12. package/src/parsing/__mocks__/mock-file-stream.js +4 -6
  13. package/src/parsing/__mocks__/utils.js +24 -35
  14. package/src/parsing/archive-header-parser.js +28 -30
  15. package/src/parsing/archive-header-parser.test.js +169 -0
  16. package/src/parsing/file-header-parser.js +45 -48
  17. package/src/parsing/file-header-parser.test.js +272 -0
  18. package/src/parsing/marker-header-parser.js +21 -21
  19. package/src/parsing/marker-header-parser.test.js +54 -0
  20. package/src/parsing/terminator-header-parser.js +8 -11
  21. package/src/parsing/terminator-header-parser.test.js +66 -0
  22. package/src/rar-file-bundle.js +10 -10
  23. package/src/rar-file-bundle.test.js +85 -0
  24. package/src/rar-file-chunk.js +5 -5
  25. package/src/rar-file-chunk.test.js +44 -0
  26. package/src/rar-files-package.js +19 -20
  27. package/src/{__tests__/rar-files-package-test.js → rar-files-package.test.js} +79 -84
  28. package/src/rar-stream.test.js +46 -0
  29. package/src/stream-utils.js +6 -11
  30. package/src/stream-utils.test.js +28 -0
  31. package/src/__tests__/rar-file-bundle-test.js +0 -85
  32. package/src/__tests__/rar-file-chunk-test.js +0 -44
  33. package/src/__tests__/rar-stream-test.js +0 -46
  34. package/src/__tests__/stream-utils-test.js +0 -27
  35. package/src/parsing/__mocks__/mock-parsers.js +0 -13
  36. package/src/parsing/__tests__/archive-header-parser-test.js +0 -148
  37. package/src/parsing/__tests__/file-header-parser-test.js +0 -246
  38. package/src/parsing/__tests__/marker-header-parser-test.js +0 -54
  39. package/src/parsing/__tests__/terminator-header-parser-test.js +0 -66
@@ -0,0 +1,3 @@
1
+ {
2
+ "cSpell.words": ["ackno"]
3
+ }
package/README.md CHANGED
@@ -1,41 +1,43 @@
1
1
  # rar-stream
2
+
2
3
  [![Build Status](https://api.travis-ci.org/1313/rar-stream.svg)](https://travis-ci.org/1313/rar-stream)
3
4
 
4
5
  Library for _"unpacking"_ and reading files inside rar archives as node Readable streams.
5
6
 
6
- __Note: Requires node version >= 8.0.0__
7
+ **Note: Requires node version >= 8.0.0**
7
8
 
8
- __Note: Decompression is not implemented at the moment__
9
+ **Note: Decompression is not implemented at the moment**
9
10
 
10
11
  ## Getting Started
11
- Below example shows howto unpack local rar files by piping the inner files to the file system.
12
+
13
+ Below example shows how to unpack local rar files by piping the inner files to the file system.
12
14
 
13
15
  ```javascript
14
- const fs = require('fs');
15
- const path = require('path');
16
- const { RarFilesPackage } = require('rar-stream');
16
+ const fs = require("fs");
17
+ const path = require("path");
18
+ const { RarFilesPackage } = require("rar-stream");
17
19
  const CWD = process.cwd();
18
20
  const localRarFiles = [
19
- path.resolve(CWD, './file.r00'),
20
- path.resolve(CWD, './file.r01'),
21
- path.resolve(CWD, './file.r02'),
22
- path.resolve(CWD, './file.rar')
21
+ path.resolve(CWD, "./file.r00"),
22
+ path.resolve(CWD, "./file.r01"),
23
+ path.resolve(CWD, "./file.r02"),
24
+ path.resolve(CWD, "./file.rar"),
23
25
  ];
24
26
 
25
27
  const rarFilesPackage = new RarFilesPackage(localRarFiles);
26
28
 
27
29
  async function writeInnerRarFilesToDisk() {
28
- const innerFiles = await rarFilesPackage.parse();
29
- for(const innerFile of innerFiles) {
30
- innerFile
31
- .createReadStream({ start: 0, end: innerFile.length - 1})
32
- .pipe(fs.createWriteStream(innerFile.name));
33
- }
30
+ const innerFiles = await rarFilesPackage.parse();
31
+ for (const innerFile of innerFiles) {
32
+ innerFile
33
+ .createReadStream({ start: 0, end: innerFile.length - 1 })
34
+ .pipe(fs.createWriteStream(innerFile.name));
35
+ }
34
36
  }
35
37
 
36
38
  writeInnerRarFilesToDisk();
37
-
38
39
  ```
40
+
39
41
  See [example/webtorrent.js](example/webtorrent.js) for a more advanced example.
40
42
 
41
43
  ### Installing
@@ -51,19 +53,22 @@ npm i rar-stream
51
53
  ### RarFilesPackage Api
52
54
 
53
55
  #### Methods:
54
- Method | Description
55
- ------|------------
56
- _constructor_ | Takes an array of local file paths as strings or instances that satifies the [`FileMedia`](#filemedia-interface) interface mentioned below.
57
- parse | Parses all rar files and returns a Promise with [`InnerFile`](#innerfile-api)s.
56
+
57
+ | Method | Description |
58
+ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
59
+ | _constructor_ | Takes an array of local file paths as strings or instances that satifies the [`FileMedia`](#filemedia-interface) interface mentioned below. |
60
+ | parse | Parses all rar files and returns a Promise with [`InnerFile`](#innerfile-api)s. |
58
61
 
59
62
  #### Events:
60
- Event | Description
61
- ------|------------
62
- parsing-start | Emitted when the parsing is started, happens when you call `parse`. Event args are a bundle represntation of all the rar files passed to the constructor.
63
- file-parsed | Emitted each time a rar file is parsed. The event argument is the RarFile just parsed, i.e `.rxx` in the chain.
64
- parsing-complete | Emitted when the parsing is completed. The event argument is an array of all the parsed [`InnerFile`](#innerfile-api)s.
63
+
64
+ | Event | Description |
65
+ | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
66
+ | parsing-start | Emitted when the parsing is started, happens when you call `parse`. Event args are a bundle represntation of all the rar files passed to the constructor. |
67
+ | file-parsed | Emitted each time a rar file is parsed. The event argument is the RarFile just parsed, i.e `.rxx` in the chain. |
68
+ | parsing-complete | Emitted when the parsing is completed. The event argument is an array of all the parsed [`InnerFile`](#innerfile-api)s. |
65
69
 
66
70
  #### Example
71
+
67
72
  ```
68
73
  const rarFilesPackage = new RarFilesPackage(localRarFiles);
69
74
  rarFilesPackage.on('parsing-start', rarFiles => console.log(rarFiles))
@@ -73,30 +78,36 @@ const innerFiles = await rarFilesPackage.parse();
73
78
  ```
74
79
 
75
80
  ### InnerFile Api
81
+
76
82
  Implements the [`FileMedia`](#filemedia-interface) interface.
77
83
 
78
84
  #### Methods:
79
- Method | Description
80
- ------|------------
81
- createReadStream({start: number, end: number}) | Returns a `Readable` stream. The start and end interval is inclusive.
82
- readToEnd | Returns a Promise with a Buffer containing all the content of the file.
85
+
86
+ | Method | Description |
87
+ | ---------------------------------------------- | ----------------------------------------------------------------------- |
88
+ | createReadStream({start: number, end: number}) | Returns a `Readable` stream. The start and end interval is inclusive. |
89
+ | readToEnd | Returns a Promise with a Buffer containing all the content of the file. |
83
90
 
84
91
  #### Properties:
85
- Property | Description
86
- ------|------------
87
- name | The name of the file
88
- length | Returns the total number of bytes of the file
92
+
93
+ | Property | Description |
94
+ | -------- | --------------------------------------------- |
95
+ | name | The name of the file |
96
+ | length | Returns the total number of bytes of the file |
89
97
 
90
98
  #### Example
99
+
91
100
  ```
92
101
  const innerFiles = await rarStreamPackage.parse();
93
102
  const innerFileStream = innerFiles[0].createReadStream({ start: 0, end: 30});
94
103
  ```
95
104
 
96
105
  ### _FileMedia Interface_
97
- This is loosely enforced interface that makes this module interoptable with other node modules such as [`torrent-stream`](https://www.npmjs.com/package/torrent-stream) or [`webtorrent`](https://www.npmjs.com/package/webtorrent).
106
+
107
+ This is loosely enforced interface that makes this module interoptable with other node modules such as [`torrent-stream`](https://www.npmjs.com/package/torrent-stream) or [`webtorrent`](https://www.npmjs.com/package/webtorrent).
98
108
 
99
109
  Should have the following shape:
110
+
100
111
  ```javascript
101
112
  // FileMedia
102
113
  {
@@ -104,7 +115,7 @@ Should have the following shape:
104
115
  name: string,
105
116
  length: number // Length or size of the file in bytes
106
117
  }
107
-
118
+
108
119
  // Interval
109
120
  // start and end should be inclusive.
110
121
  {
@@ -113,19 +124,19 @@ Should have the following shape:
113
124
  }
114
125
  ```
115
126
 
116
-
117
127
  ## Development
118
128
 
119
129
  ### Running the tests
120
130
 
121
131
  Run tests with:
132
+
122
133
  ```
123
134
  npm test
124
135
  ```
125
136
 
126
137
  ### Built With
127
138
 
128
- * [binary](https://www.npmjs.com/package/binary) - For parsing rar headers.
139
+ - [binary](https://www.npmjs.com/package/binary) - For parsing rar headers.
129
140
 
130
141
  ### Contributing
131
142
 
@@ -133,9 +144,8 @@ Post a new issue if you'd like to contribute in any way.
133
144
 
134
145
  ### Versioning
135
146
 
136
- We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/1313/rar-stream/tags).
147
+ We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/1313/rar-stream/tags).
137
148
 
138
149
  ## License
139
150
 
140
151
  This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
141
-