LinuxCommandLibrary

asar

Package and unpackage Electron app source code

TLDR

Archive a file or directory

$ asar pack [path/to/input_file_or_directory] [path/to/output_archive.asar]
copy

Extract an archive
$ asar extract [path/to/archive.asar]
copy

Extract a specific file from an archive
$ asar extract-file [path/to/archive.asar] [file]
copy

List the contents of an archive file
$ asar list [path/to/archive.asar]
copy

SYNOPSIS

asar command [options] src [dest]

Common commands:
asar pack src_dir dest.asar
asar list archive.asar
asar extract archive.asar dest_dir
asar extract-file archive.asar file_path

PARAMETERS

pack
    Packs a directory (src_dir) into a new .asar archive (dest.asar).

list
    Lists the files contained within an .asar archive.

extract
    Extracts the entire content of an .asar archive to a specified directory (dest_dir).

extract-file
    Extracts a single file from an .asar archive at the specified internal file_path.

--unpack
    Used with 'pack'. Specifies a glob pattern for files that should NOT be packed into the .asar archive but extracted separately. For example: --unpack *.node.

--unpack-dir
    Used with 'pack'. Specifies a glob pattern for directories that should NOT be packed into the .asar archive. For example: --unpack-dir **/node_modules.

--help
    Displays help information for the command or specific sub-command.

--version
    Shows the current version of the asar utility.

DESCRIPTION

asar is a simple, tar-like archive format used by Electron to concatenate application source code into a single file. It stands for Atom Shell Archive. This format helps protect the source code from casual inspection and can improve performance by reducing file I/O overhead during application startup, especially on Windows where path lengths can be an issue. It allows developers to bundle all JavaScript, CSS, HTML, and other assets into a single .asar archive file. The Electron framework can then read files from this archive directly, treating it like a virtual file system. This command-line utility provides functionalities to pack, list, and extract content from these archives.

CAVEATS

The asar command is not a standard Linux utility and requires Node.js and npm for installation. It is primarily used within the Electron development ecosystem for packaging applications. Unlike traditional archive formats like tar or zip, asar archives are designed to be read directly by the Electron runtime, not typically for general-purpose archiving.

INSTALLATION

The asar command-line utility can be installed globally via npm (Node Package Manager), assuming Node.js is already installed on your system:
npm install -g asar
This command makes the asar executable available in your system's PATH, allowing you to run it from any directory.

HISTORY

The asar format and utility were developed by GitHub as part of the Atom Shell project, which was later rebranded as Electron. It was created specifically to address the unique packaging and performance requirements of desktop applications built with web technologies, offering a straightforward way to bundle thousands of small files into a single, easily distributable package.

SEE ALSO

electron, npm(1), tar(1), zip(1)

Copied to clipboard