---
title: "@vltpkg/tar: unpack — vlt docs"
description: "Documentation for the vlt client and the vlt registry."
url: "https://docs.vlt.io/client/api-reference/tar/unpack"
image: "https://docs.vlt.io/og/client/api-reference/tar/unpack"
lang: "en"
---

# unpack

## Type Aliases

### FileEntry

```ts
type FileEntry = object;
```

Defined in: tar/src/unpack.ts:189

A file parsed out of a tarball, at its destination path.

#### Type declaration

| Name         | Type      | Description                                                   |
| ------------ | --------- | ------------------------------------------------------------- |
| `body`       | `Buffer`  | -                                                             |
| `dir`        | `false`   | -                                                             |
| `executable` | `boolean` | written with the exec bit: world-executable in the tar header |
| `path`       | `string`  | -                                                             |

## Functions

### cacheEntryBody()

```ts
function cacheEntryBody(entry): Buffer
```

Defined in: tar/src/unpack.ts:435

The tarball inside a vlt cache entry file: the file starts with a 4-byte big-endian length of the head, and the body follows the head. The length is read from the same bytes as the body, so an entry that `cache-unzip` rewrote with a different head is still read correctly.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `entry`   | `Buffer` |

#### Returns

`Buffer`

---

### checkFs()

```ts
function checkFs(
   h, 
   tarDir, 
   target): h is { path: string }
```

Defined in: tar/src/unpack.ts:297

#### Parameters

| Parameter | Type                    |
| --------- | ----------------------- |
| `h`       | { `path`: `string`; }   |
| `h.path`? | `string`                |
| `tarDir`  | `undefined` \| `string` |
| `target`  | `string`                |

#### Returns

`h is { path: string }`

---

### storeLayout()

```ts
function storeLayout(
   tarData, 
   dir, 
   format?): object
```

Defined in: tar/src/unpack.ts:734

What a tarball explodes to in the global store at `dir`: its sidecar index, files and package.json `bin` target paths. Same parsing and path safety as [unpackSync](https://docs.vlt.io/client/api-reference/tar/unpack.md#unpacksync), and the same `format` rule -- only brotli has to be declared. No IO. Throws if the tarball has no valid package.json.

#### Parameters

| Parameter | Type                                                                                          |
| --------- | --------------------------------------------------------------------------------------------- |
| `tarData` | `Buffer`                                                                                      |
| `dir`     | `string`                                                                                      |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) |

#### Returns

`object`

| Name       | Type                                                                                   |
| ---------- | -------------------------------------------------------------------------------------- |
| `binFiles` | `string`\[]                                                                            |
| `files`    | [`FileEntry`](https://docs.vlt.io/client/api-reference/tar/unpack.md#fileentry)\[]     |
| `index`    | [`StoreIndex`](https://docs.vlt.io/client/api-reference/tar/store-index.md#storeindex) |

---

### tmpName()

```ts
function tmpName(target): string
```

Defined in: tar/src/unpack.ts:472

Sibling temp path used to build `target` before renaming it in.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `target`  | `string` |

#### Returns

`string`

---

### unpack()

```ts
function unpack(
   tarData, 
   target, 
   format?, 
path?): Promise<void>
```

Defined in: tar/src/unpack.ts:338

`path`: only what is under that dir of the tarball's root dir, as the root (eg a package in a git archive of its monorepo).

#### Parameters

| Parameter | Type                                                                                          |
| --------- | --------------------------------------------------------------------------------------------- |
| `tarData` | `Buffer`                                                                                      |
| `target`  | `string`                                                                                      |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) |
| `path`?   | `string`                                                                                      |

#### Returns

`Promise`<`void`>

---

### unpackCacheEntryParallel()

```ts
function unpackCacheEntryParallel(
   file, 
   target, 
   format?, 
path?): Promise<void>
```

Defined in: tar/src/unpack.ts:458

Same, inflating on libuv's threadpool. See [unpackParallel](https://docs.vlt.io/client/api-reference/tar/unpack.md#unpackparallel).

#### Parameters

| Parameter | Type                                                                                          |
| --------- | --------------------------------------------------------------------------------------------- |
| `file`    | `string`                                                                                      |
| `target`  | `string`                                                                                      |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) |
| `path`?   | `string`                                                                                      |

#### Returns

`Promise`<`void`>

---

### unpackCacheEntrySync()

```ts
function unpackCacheEntrySync(
   file, 
   target, 
   format?, 
   path?): void
```

Defined in: tar/src/unpack.ts:447

Unpack the tarball in the vlt cache entry `file`. See [cacheEntryBody](https://docs.vlt.io/client/api-reference/tar/unpack.md#cacheentrybody), and [unpack](https://docs.vlt.io/client/api-reference/tar/unpack.md#unpack) for `path`.

#### Parameters

| Parameter | Type                                                                                          |
| --------- | --------------------------------------------------------------------------------------------- |
| `file`    | `string`                                                                                      |
| `target`  | `string`                                                                                      |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) |
| `path`?   | `string`                                                                                      |

#### Returns

`void`

---

### unpackFileParallel()

```ts
function unpackFileParallel(
   file, 
   target, 
   offset, 
format?): Promise<void>
```

Defined in: tar/src/unpack.ts:404

[unpackParallel](https://docs.vlt.io/client/api-reference/tar/unpack.md#unpackparallel) reading the tarball from a file, so the read comes off the main thread as well. See [unpackFileSync](https://docs.vlt.io/client/api-reference/tar/unpack.md#unpackfilesync) for what `offset` is for.

#### Parameters

| Parameter | Type                                                                                          | Default value |
| --------- | --------------------------------------------------------------------------------------------- | ------------- |
| `file`    | `string`                                                                                      | `undefined`   |
| `target`  | `string`                                                                                      | `undefined`   |
| `offset`  | `number`                                                                                      | `0`           |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) | `undefined`   |

#### Returns

`Promise`<`void`>

---

### unpackFileSync()

```ts
function unpackFileSync(
   file, 
   target, 
   offset, 
   format?): void
```

Defined in: tar/src/unpack.ts:421

Unpack a tarball straight from a file on disk, skipping `offset` leading bytes. Used to extract from a cache entry in place, so the tarball never lands in the registry client's in-memory cache.

#### Parameters

| Parameter | Type                                                                                          | Default value |
| --------- | --------------------------------------------------------------------------------------------- | ------------- |
| `file`    | `string`                                                                                      | `undefined`   |
| `target`  | `string`                                                                                      | `undefined`   |
| `offset`  | `number`                                                                                      | `0`           |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) | `undefined`   |

#### Returns

`void`

---

### unpackParallel()

```ts
function unpackParallel(
   tarData, 
   target, 
   format?, 
path?): Promise<void>
```

Defined in: tar/src/unpack.ts:385

Inflate off the main thread, then write the files on it.

zlib's async API hands the decompress to libuv's threadpool, so concurrent extractions inflate in parallel -- on `UV_THREADPOOL_SIZE` threads, 4 by default -- while the main thread stays free. The writes then take the sync path, which is faster than the async writers (a libuv round trip per file costs more than the IO itself).

Splitting the two is the whole point: parallel decompression without giving up the fast writer. It matters most for brotli, whose inflate costs more CPU than gzip's, but it speeds up `.tgz` installs too.

#### Parameters

| Parameter | Type                                                                                          |
| --------- | --------------------------------------------------------------------------------------------- |
| `tarData` | `Buffer`                                                                                      |
| `target`  | `string`                                                                                      |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) |
| `path`?   | `string`                                                                                      |

#### Returns

`Promise`<`void`>

---

### unpackSync()

```ts
function unpackSync(
   tarData, 
   target, 
   format?, 
   path?): void
```

Defined in: tar/src/unpack.ts:355

Same as [unpack](https://docs.vlt.io/client/api-reference/tar/unpack.md#unpack), but blocking. Faster: the async writers pay a libuv round trip per file, which costs more than the IO itself.

#### Parameters

| Parameter | Type                                                                                          |
| --------- | --------------------------------------------------------------------------------------------- |
| `tarData` | `Buffer`                                                                                      |
| `target`  | `string`                                                                                      |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) |
| `path`?   | `string`                                                                                      |

#### Returns

`void`

---

### unpackToStoreSync()

```ts
function unpackToStoreSync(
   tarData, 
   dir, 
   format?): object
```

Defined in: tar/src/unpack.ts:796

Explode a tarball into `dir` for the global store and return its sidecar index (see [storeLayout](https://docs.vlt.io/client/api-reference/tar/unpack.md#storelayout)), written straight into `dir` (which must not exist; the caller renames it into place). Same modes as [unpackSync](https://docs.vlt.io/client/api-reference/tar/unpack.md#unpacksync) followed by reify's bin chmod. Throws, writing nothing, without a valid package.json. Removes `dir` on failure.

#### Parameters

| Parameter | Type                                                                                          |
| --------- | --------------------------------------------------------------------------------------------- |
| `tarData` | `Buffer`                                                                                      |
| `dir`     | `string`                                                                                      |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) |

#### Returns

`object`

| Name    | Type                                                                                   |
| ------- | -------------------------------------------------------------------------------------- |
| `index` | [`StoreIndex`](https://docs.vlt.io/client/api-reference/tar/store-index.md#storeindex) |

## References

### TarballFormat

Re-exports [TarballFormat](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat)
