The Simplest and Most Powerful Archive File Format Ever Made

.asar is a simple .tar-like archive format with impressive features.

Shalitha Suranga
Feb 14 · 3 min read
An image of a book rack with a lot of books
An image of a book rack with a lot of books
Photo by Ashim D’Silva on Unsplash

When the file count is increasing, file management is a bit complex and time-consuming. Archive file formats are helping us to create a single file by merging multiple files and directories. Therefore, for users, they can make one file from a set of rarely accessed files. Whenever they need to access the files, they can extract them as typical files and directories. For developers, they can make a single file for storing resources rather than storing all resources separately on disk. That will make the particular software more portable and easy to share as well.

Last week, I was looking for an archive file format to store application resources. Application resources were just a bunch of JavaScript files and graphics. I had some strict requirements for the expected archive format: random access support, extracting data without a third-party library, and an uncompressed structure.

I found that the .asar archive format exactly matches my requirements. If you are looking for a simple but powerful archive format, .asar is indeed the option for you.

.asar internals

The entire structure is a piece of cake. .asar has the following internal format.

| UInt32: header_size | String: header | Bytes: file1 | ... | Bytes: file42 |

header_size is an 8-bit binary data segment that stores the size of the header segment. Theheader segment stores the directory tree of all stored files in JSON format. After that, it’s all about the content of the concatenated files like the .tar archive format.

The header’s JSON structure looks like shown below.

If the particular element is a directory, it has the files attribute with its child contents. If there is a file, it will contain two properties: offset for indexing, and size attribute for the size of the file.

How to pack files

.asar has a great CLI. We can use the CLI to create archives from the directories we have. This packing process will make the header by analyzing the provided directory structure. Also, it will concatenate all files accordingly.

Packing files using the CLI.

$ asar pack <directory> <filename>

We can pack files programmatically as well with the help of its npm package.

How to unpack files

The CLI will also help you with the unpacking process. Since there is no hard compression, the process is pretty fast. This process will parse the header JSON, and for each node, it will create a file or a directory. Parsing is easy because we have the exact structure of the directories in the header. Also, we have the size and the offset of each file.

Unpacking files using the CLI.

$ asar extract <archive_filename> <directory> 

We can do the same programmatically as well.

Random access

The .asar archive format looks like the .tar format internally. Because both .tar and .asar store file information in sequential order. Additionally, .asar supports random access to any file. In other words, if we have the file path, we can extract only the required file without touching other files. Random accessing is a helpful feature for application resource files because any resource file can be loaded into the physical memory instantly with good performance.

Importantly, this random accessing logic could be implemented by ourselves without even using a third-party library because .asar structure is undoubtedly simple. For example, I made the following C++ implementation for random accessing and resource handling.

.asar is a very flexible format. You will be able to extend the file attributes according to your requirements. For example, if you need to store created date of each file, you can modify the directory tree JSON by adding a new attribute.

The Startup

Get smarter at building your thing. Join The Startup’s +787K followers.

Thanks to Athif Shaffy

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Shalitha Suranga

Written by

Programmer | Author of Neutralinojs and Jerverless | Technical Writer

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +787K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store