Install
Install the package for application code, or add `nar` globally when you want the command available in any shell.
npm install @nodearchive/nodearchive
pnpm add @nodearchive/nodearchive
yarn add @nodearchive/nodearchive
bun add @nodearchive/nodearchive
npm i -g @nodearchive/nodearchive
bun add --global @nodearchive/nodearchive
CLI
Keep the command surface small: `pack` to write archives, `unpack` to extract them, and `--help` when you need the flags.
nar pack ./src ./dist/app.nar --passThru
nar pack ./src ./dist/app.zip --outFormat zip --passThru
nar pack ./package.json ./dist/meta.nar --force
nar pack ./src ./dist/app.nar --update --passThru
nar unpack ./dist/app.nar ./out --force --passThru
nar unpack ./incoming.zip ./out --force
nar unpack ./dist/app.nar ./preview --whatIf --passThru
API
The API stays small on purpose: `pack()` writes archives, `unpack()` reads them, the package works from both `import` and `require()`, and `outFormat` switches the pack target when `.nar` is not the format you want.
import { pack, unpack } from '@nodearchive/nodearchive'
await pack({
literalPath: ['src', 'package.json'],
destinationPath: './dist/app.nar',
force: true,
})
await unpack({
path: './dist/app.nar',
destinationPath: './out',
force: true,
})
const { pack, unpack } = require('@nodearchive/nodearchive')
async function main() {
const archive = await pack({ blob: 'hello world' })
const restored = await unpack({ blob: archive })
console.log(Buffer.from(restored).toString('utf8'))
}
main()
await pack({
literalPath: ['src'],
destinationPath: './dist/app.zip',
outFormat: 'zip',
})
await pack({
literalPath: ['src'],
destinationPath: './dist/app.tgz',
})
const archive = await pack({ blob: 'hello world' })
const restored = await unpack({ blob: archive })
console.log(Buffer.from(restored).toString('utf8'))