# @cogeotiff/chunk

> **Deprecated**: this module has moved to `@chunkd/core`

Latest version **4.4.0** (published 2021-07-23) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @cogeotiff/chunk
pnpm add @cogeotiff/chunk
yarn add @cogeotiff/chunk
bun add @cogeotiff/chunk
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.4.0 |
| Published | 2021-07-23 |
| First published | 2021-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 122.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 117 |
| Author | Blayne Chard |
| Maintainers | blacha |

## Links

- npm: https://www.npmjs.com/package/@cogeotiff/chunk
- Repository: https://github.com/blacha/cogeotiff
- Homepage: https://github.com/blacha/cogeotiff#readme
- Issues: https://github.com/blacha/cogeotiff/issues
- npm.io page: https://npm.io/package/@cogeotiff/chunk

## Recent versions

- 4.4.0 (latest) — 2021-07-23
- 4.3.0 — 2021-06-22
- 4.2.0 — 2021-03-25
- 4.1.2 — 2021-03-18
- 4.1.0 — 2021-02-23

## README

# Chunked object reading

**Deprecated**: this module has moved to `@chunkd/core`


Split up a file into chunks and then read the chunks as needed.

## Example Sources
- File - [@cogeotiff/source-file](https://www.npmjs.com/package/@cogeotiff/source-file)
- AWS - [@cogeotiff/source-aws](https://www.npmjs.com/package/@cogeotiff/source-aws)
- Url - [@cogeotiff/source-url](https://www.npmjs.com/package/@cogeotiff/source-url)

### Example Usage
Fetching Data
```typescript
const source = new SourceUrl('https://example.com/foo')
// Read 1KB chunks
source.chunkSize = 1024;

// Read the first 2KB of the file, or two chunks of data, this will be one HTTP Range requests
if (!source.hasBytes(0, 2048)) await source.loadBytes(0, 2048)

const bytes = source.bytes(0, 2048);
```

Fetching multiple ranges at the same time

```typescript
const source = new SourceUrl('https://example.com/foo')
// Read 1KB chunks
source.chunkSize = 1024;

// Read in the first two KB and 1KB starting at 4KB
// This will do one HTTP Range request for all of the data even though 2048-4096 has not been requested
// Chunks 0 (0-1024), 1 (1024-2048), 2 (2048-3096) 3 (3096-4096) and 4 (4096 - 5120) will be fetched
await Promise.all([
    source.loadBytes(0, 2048), 
    source.loadBytes(4096, 1024)
]) 

const bytes = source.bytes(0, 5120);
```


Reading raw bytes
```typescript
const source = new SourceUrl('https://example.com/foo')

if (!source.hasBytes(0, 1024)) await source.loadBytes(0, 1024)
// Read a UInt8 starting at offset 0
const firstNumber = source.uint8(0);
// Read a buffer from offset 10, with length of 100
const firstBuffer = source.bytes(10, 100)
```

---
_Source: https://npm.io/package/@cogeotiff/chunk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
