You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**rar.js** provides a pure javascript implementation of the rar format, allowing you to extract or manipulate packed data client-side and server-side.
5
4
6
5
Multiple inputs are supported: AJAX, File API (HTML5) and local disk (NodeJS).
7
6
8
-
**rar.js** makes use of [dataview-extra](https://github.com/43081j/dataview-extra) and [reader.js](https://github.com/43081j/reader.js).
7
+
## Example
9
8
10
-
**This is a very new utility/library, please see the list below for what may be missing.**
9
+
Using **rar.js** is fairly straight forward.
10
+
11
+
```javascript
12
+
Rar.fromLocal('myfile.rar').then((archive) => {
13
+
// Use archive here
14
+
console.log(archive.entries);
15
+
});
11
16
12
-
**TODO & Potential Features**
17
+
Rar.fromUri('/test.rar').then((archive) => {
18
+
// Use archive here
19
+
});
20
+
21
+
Rar.fromFile(input.files[0]).then((archive) => {
22
+
// Use archive here
23
+
});
24
+
```
25
+
26
+
## Unsupported features (TODO)
13
27
14
28
* Large file support (currently the entire file will be in memory when `RarArchive.get` is called)
15
29
* Decompression support
16
30
* Encryption support
17
31
* Recognise volumes/split archives
18
32
* Parse other entries (e.g. comments)
19
33
20
-
Example
21
-
===
34
+
## Saving files
22
35
23
-
Using **rar.js** is fairly straight forward.
36
+
By using `RarArchive#get(file)`, you can retrieve a `Blob` of a specified file within the archive.
24
37
25
38
```javascript
26
-
var archive =RarArchive(file, function(err) {
27
-
if(err) {
28
-
// An error occurred (not a rar, read error, etc)
29
-
return;
30
-
}
31
-
// Use archive
32
-
});
39
+
constfile=archive.get(archive.entries[0]);
40
+
consturl=URL.createObjectURL(file);
41
+
// Do something with url here
42
+
// like creating an <a> tag with the download attribute set
33
43
```
34
44
35
-
In this example, the callback is called when the archive has been opened and validated successfully. If the archive is of an invalid format or cannot be read, an appropriate error will be passed.
36
-
37
-
Within the callback, `archive.entries` has been populated with the files (note you may use `this.entries` in the callback too).
38
-
39
-
Each entry is a `RarEntry` instance.
40
-
41
-
Saving files
42
-
===
43
-
44
-
By using `RarArchive.get(file, callback)`, you can retrieve a `Blob` of a specified file within the archive.
45
-
46
-
What you do with this `Blob` is upto you. A common thing to do would be to create an object URL using `URL.createObjectURL(Blob)` and redirect the user to it or create an `<a>` element with the `download` attribute (HTML5) set to the file name.
47
-
48
-
Split Volumes
49
-
===
45
+
### Split Volumes
50
46
51
47
When dealing with entries you have retrieved via `RarArchive.get()`, make sure you check the `RarEntry.partial` boolean.
52
48
53
49
If this boolean is true, sending/saving the `Blob` will result in a partial file. You must request that the user open the previous or next volume and prepend/append to the `Blob` to be able to retrieve the full file.
54
50
55
51
To find out if the file is continued in a previous or next volume, see `RarEntry.continues` and `RarEntry.continuesFrom`.
56
52
57
-
RarArchive
58
-
===
53
+
## RarArchive
59
54
60
-
*`RarArchive(options, callback)` If options is a string, it is assumed to be a URL. If it is a File instance, it will be treated as such. `callback` will be called when the archive has been validated and is ready.
61
-
*`RarArchive.entries` An array of `RarEntry` instances contained within this archive
62
-
*`RarArchive.get(RarEntry, callback)` Retrieves the specified `RarEntry` and passed a `Blob` of it to `callback`
63
-
64
-
When creating an instance of `RarArchive`, the data source is guessed based on data type. If it is a string, it is assumed to be a URL and will be requested over HTTP. If it is a `File` instance, it will be read as one.
65
-
66
-
In the case that you want to specify the type manually or want to read a local file, you must pass it in the options like so:
0 commit comments