rar.js provides a pure javascript implementation of the rar format, allowing you to extract or manipulate packed data client-side and server-side.
Multiple inputs are supported: AJAX, File API (HTML5) and local disk (NodeJS).
Using rar.js is fairly straight forward.
Rar.fromLocal('myfile.rar').then((archive) => {
// Use archive here
console.log(archive.entries);
});
Rar.fromUri('/test.rar').then((archive) => {
// Use archive here
});
Rar.fromFile(input.files[0]).then((archive) => {
// Use archive here
});- Large file support (currently the entire file will be in memory when
RarArchive.getis called) - Decompression support
- Encryption support
- Recognise volumes/split archives
- Parse other entries (e.g. comments)
By using RarArchive#get(file), you can retrieve a Blob of a specified file within the archive.
const file = archive.get(archive.entries[0]);
const url = URL.createObjectURL(file);
// Do something with url here
// like creating an <a> tag with the download attribute setWhen dealing with entries you have retrieved via RarArchive.get(), make sure you check the RarEntry.partial boolean.
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.
To find out if the file is continued in a previous or next volume, see RarEntry.continues and RarEntry.continuesFrom.
Rar.fromFile(file)wherefileis a HTML5FileinstanceRar.fromLocal(path)wherepathis a string of a local filesystem pathRar.fromUri(uri)whereuriis a string of a URI
All three of these entrypoints return a Promise which resolves to a RarArchive.
RarArchive#entriesAn array ofRarEntryinstances contained within this archiveRarArchive#get(RarEntry)Retrieves the specifiedRarEntryresolves a promise with aBlob
nameFile namepathFile path within the archive, including file namesizeSize of the unpacked filesizePackedSize of the packed filecrcCRC of the fileoffsetOffset within the archiveblockSizeSize of this entry within the archive (including headers)headerSizeSize of the header for this entryencryptedBoolean specifying if the file is password protected or notversionRAR version usedtimeDate/time string for the filemethodCompression method used, will equal one of the method constantsosOperating system used (Windows,MS-DOS,OS/2,Unix,MacorBeOS)partialBoolean specifying if the file is partial available due to split volumes. UseRarEntry.continuesandRarEntry.continuesFrom.continuesFromBoolean specifying if the file continues from a previous volumecontinuesBoolean specifying if the file continues into the next volume
The following constants also exist for use with RarEntry.method:
Rar.RarMethod.STORERar.RarMethod.FASTESTRar.RarMethod.FASTRar.RarMethod.NORMALRar.RarMethod.GOODRar.RarMethod.BEST
MIT