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.get
is 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 set
When 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)
wherefile
is a HTML5File
instanceRar.fromLocal(path)
wherepath
is a string of a local filesystem pathRar.fromUri(uri)
whereuri
is a string of a URI
All three of these entrypoints return a Promise
which resolves to a RarArchive
.
RarArchive#entries
An array ofRarEntry
instances contained within this archiveRarArchive#get(RarEntry)
Retrieves the specifiedRarEntry
resolves a promise with aBlob
name
File namepath
File path within the archive, including file namesize
Size of the unpacked filesizePacked
Size of the packed filecrc
CRC of the fileoffset
Offset within the archiveblockSize
Size of this entry within the archive (including headers)headerSize
Size of the header for this entryencrypted
Boolean specifying if the file is password protected or notversion
RAR version usedtime
Date/time string for the filemethod
Compression method used, will equal one of the method constantsos
Operating system used (Windows
,MS-DOS
,OS/2
,Unix
,Mac
orBeOS
)partial
Boolean specifying if the file is partial available due to split volumes. UseRarEntry.continues
andRarEntry.continuesFrom
.continuesFrom
Boolean specifying if the file continues from a previous volumecontinues
Boolean specifying if the file continues into the next volume
The following constants also exist for use with RarEntry.method
:
Rar.RarMethod.STORE
Rar.RarMethod.FASTEST
Rar.RarMethod.FAST
Rar.RarMethod.NORMAL
Rar.RarMethod.GOOD
Rar.RarMethod.BEST
MIT