# AttachmentReader

Defined in: [zaun/js/index.d.ts:710](https://github.com/zaunchat/zaun-client/blob/main/zaun/js/index.d.ts#L710)

An attachment read while it downloads. Every byte a read gives is plaintext of a chunk
whose SHA-256 the file's description (sent by the host over the post-quantum connection)
named. The attachment's own SHA3-256, and XFTP's whole-file digest and tag, are checked
once every chunk was read in order: `verified()`.

## Constructors

### Constructor

> **new AttachmentReader**(): `AttachmentReader`

#### Returns

`AttachmentReader`

## Properties

### attachment

> `readonly` **attachment**: [`Attachment`](/docs/reference/js/zaun-client/classes/attachment/)

Defined in: [zaun/js/index.d.ts:711](https://github.com/zaunchat/zaun-client/blob/main/zaun/js/index.d.ts#L711)

***

### raw

> `readonly` **raw**: `RawAttachmentReader`

Defined in: [zaun/js/index.d.ts:712](https://github.com/zaunchat/zaun-client/blob/main/zaun/js/index.d.ts#L712)

***

### size

> `readonly` **size**: `number`

Defined in: [zaun/js/index.d.ts:714](https://github.com/zaunchat/zaun-client/blob/main/zaun/js/index.d.ts#L714)

The attachment's size in bytes.

## Methods

### close()

> **close**(): `void`

Defined in: [zaun/js/index.d.ts:726](https://github.com/zaunchat/zaun-client/blob/main/zaun/js/index.d.ts#L726)

Stops the download; waiting and later reads reject with `closed`.

#### Returns

`void`

***

### progress()

> **progress**(): `object`

Defined in: [zaun/js/index.d.ts:724](https://github.com/zaunchat/zaun-client/blob/main/zaun/js/index.d.ts#L724)

Encrypted bytes fetched so far (again after an eviction) and of the whole file.

#### Returns

`object`

##### fetched

> **fetched**: `number`

##### total

> **total**: `number`

***

### read()

> **read**(`offset`, `length`, `signal?`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>

Defined in: [zaun/js/index.d.ts:718](https://github.com/zaunchat/zaun-client/blob/main/zaun/js/index.d.ts#L718)

Up to `length` bytes from `offset`: fewer when the range runs past what is downloaded,
none at the end. Waits for the first chunk the range needs. `signal` gives it up
(`aborted`); a failed check rejects with `mismatch`, a closed reader with `closed`.

#### Parameters

##### offset

`number`

##### length

`number`

##### signal?

`AbortSignal`

#### Returns

`Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>

***

### verified()

> **verified**(): `Promise`\<`void`\>

Defined in: [zaun/js/index.d.ts:722](https://github.com/zaunchat/zaun-client/blob/main/zaun/js/index.d.ts#L722)

Resolves once every chunk went through the whole-file checks and the file's size and
SHA3-256 are the attachment's; rejects with `mismatch` (and fails every read after) when
not, or with why the download stopped.

#### Returns

`Promise`\<`void`\>
