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

# placement-worker

## Type Aliases

### CacheEntryJob

```ts
type CacheEntryJob = object;
```

Defined in: tar/src/placement-worker.ts:48

Unpack the tarball in a vlt cache entry file into `target`. The worker reads the file itself, so the main thread never holds or copies the body.

#### Type declaration

| Name      | Type                                                                                          | Description                                                                                   |
| --------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| `file`    | `string`                                                                                      | -                                                                                             |
| `format`? | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) | -                                                                                             |
| `id`      | `number`                                                                                      | -                                                                                             |
| `kind`    | `"cacheEntry"`                                                                                | -                                                                                             |
| `path`?   | `string`                                                                                      | as in [UnpackJob](https://docs.vlt.io/client/api-reference/tar/placement-worker.md#unpackjob) |
| `target`  | `string`                                                                                      | -                                                                                             |

---

### PlacementJob

```ts
type PlacementJob = 
  | UnpackJob
  | CacheEntryJob;
```

Defined in: tar/src/placement-worker.ts:58

---

### PlacementReply

```ts
type PlacementReply = 
  | {
  id: number;
  result: true;
 }
  | {
  code: string;
  error: string;
  id: number;
  stack: string;
 }
  | {
  ready: true;
};
```

Defined in: tar/src/placement-worker.ts:65

A worker's reply for job `id`: `true` once unpacked, or the message, stack and errno code of the error thrown, which the pool rebuilds into an Error so a worker failure looks like the inline call failing.

#### Type declaration

{ `id`: `number`; `result`: `true`; }

| Name     | Type     |
| -------- | -------- |
| `id`     | `number` |
| `result` | `true`   |

{ `code`: `string`; `error`: `string`; `id`: `number`; `stack`: `string`; }

| Name     | Type     |
| -------- | -------- |
| `code`?  | `string` |
| `error`  | `string` |
| `id`     | `number` |
| `stack`? | `string` |

{ `ready`: `true`; }

| Name    | Type   |
| ------- | ------ |
| `ready` | `true` |

---

### ReplyPort

```ts
type ReplyPort = object;
```

Defined in: tar/src/placement-worker.ts:72

A port that takes a [PlacementReply](https://docs.vlt.io/client/api-reference/tar/placement-worker.md#placementreply); the real one is `parentPort`.

#### Type declaration

| Name          | Type                |
| ------------- | ------------------- |
| `postMessage` | (`reply`) => `void` |

---

### UnpackJob

```ts
type UnpackJob = object;
```

Defined in: tar/src/placement-worker.ts:31

Unpack a tarball into `target`. The bytes arrive as an `ArrayBuffer` transferred from the main thread.

#### Type declaration

| Name         | Type                                                                                          | Description                                              |
| ------------ | --------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| `buffer`     | `ArrayBuffer`                                                                                 | -                                                        |
| `byteLength` | `number`                                                                                      | -                                                        |
| `byteOffset` | `number`                                                                                      | -                                                        |
| `format`?    | [`TarballFormat`](https://docs.vlt.io/client/api-reference/tar/module_index.md#tarballformat) | -                                                        |
| `id`         | `number`                                                                                      | -                                                        |
| `kind`       | `"unpack"`                                                                                    | -                                                        |
| `path`?      | `string`                                                                                      | only that dir of the tarball's root dir, see `unpack.ts` |
| `target`     | `string`                                                                                      | -                                                        |

## Variables

### \_\_CODE_SPLIT_SCRIPT_NAME

```ts
const __CODE_SPLIT_SCRIPT_NAME: string;
```

Defined in: tar/src/placement-worker.ts:25

Unpacking a tarball is synchronous work the main thread cannot afford: inflating it, parsing it and writing its files. While the main thread does that, no registry response is read, no manifest is parsed and no node is placed in the graph. A `PlacementPool` runs this script as a worker thread so several packages are unpacked at once, across cores, and the main thread stays free to keep the network busy.

Hardlinking a global store entry stays on the main thread: it is a fraction of a millisecond per package, and on a two-core machine the boot of the workers and the round trips never paid for themselves (measured: +48% on the placement phase of a warm install).

The build emits it as its own bundled file: the exported [\_\_CODE_SPLIT_SCRIPT_NAME](https://docs.vlt.io/client/api-reference/tar/placement-worker.md#__code_split_script_name) is the path to spawn (the source `.ts` in dev and test, the built `.js` in the bundle), and [handleJob](https://docs.vlt.io/client/api-reference/tar/placement-worker.md#handlejob) is the per-message handler, exported so it can be tested without a live worker.

## Functions

### handleJob()

```ts
function handleJob(port, job): void
```

Defined in: tar/src/placement-worker.ts:77

Run one job and post the result (or its error) back.

#### Parameters

| Parameter | Type                                                                                            |
| --------- | ----------------------------------------------------------------------------------------------- |
| `port`    | [`ReplyPort`](https://docs.vlt.io/client/api-reference/tar/placement-worker.md#replyport)       |
| `job`     | [`PlacementJob`](https://docs.vlt.io/client/api-reference/tar/placement-worker.md#placementjob) |

#### Returns

`void`
