-
-
Notifications
You must be signed in to change notification settings - Fork 3
Unpacking existing ASAR archive
To unpack an existing ASAR archive, you need to use AsarArchiveUnpacker
class. It provides methods for extracting all files, or just files you need.
First, you need to open an ASAR archive in order to start extracting files from archive. After you opened an ASAR archive, you can create an unpacker and extract files from this archive.
Here is an example of creating unpacker:
AsarArchive archive = new AsarArchive("path/to/archive.asar");
AsarArchiveUnpacker unpacker = new AsarArchiveUnpacker(archive);
Unpacker class has two events that can be occurred when unpacking whole archive.
StatusChanged
event
Occurs when archive unpacking status changed (current unpacking file changed, etc.)
AsarArchiveUnpacked
event
Occurs when archive unpacking completed successfully
To unpack file, AsarArchiveUnpacked.UnpackFileAsync()
method is used. It has a bunch of overloads that allows you to unpack file into file on disk or into data stream.
Here is an example of unpacking one file from archive:
await unpacker.UnpackFileAsync("path/within/archive/to/file.bin", "path/to/file/on/disk/file.bin");
MemoryStream outputStream = new MemoryStream(); // or any other type of stream
await unpacker.UnpackFileAsync("path/within/archive/to/file.bin", outputStream);
To unpack whole archive, you need to use AsarArchiveUnpacker.UnpackAsync(string)
method. It accepts a string with a path to directory, in which to put unpacked files from archive.
Here is an example of how to unpack whole archive into a folder:
await unpacker.UnpackAsync("path/to/unpacked/destination/");
Made with ❤️ by craftersmine