# topobuf

> Compact binary encoding for topojson data

Latest version **1.1.0** (published 2022-02-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install topobuf
pnpm add topobuf
yarn add topobuf
bun add topobuf
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-02-23 |
| First published | 2022-02-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | azavea |
| Keywords | geographic, data, buffer, protobuf, format, compression, topojson |

## Links

- npm: https://www.npmjs.com/package/topobuf
- Repository: https://github.com/azavea/topobuf
- Issues: https://github.com/azavea/topobuf/issues
- npm.io page: https://npm.io/package/topobuf

## Dependencies (3)

- [pbf](https://npm.io/package/pbf.md) ^3.2.1
- [@types/pbf](https://npm.io/package/@types/pbf.md) ^3.0.2
- [@types/topojson-specification](https://npm.io/package/@types/topojson-specification.md) ^1.0.2

## Alternatives

- [@libsql/sqlite3](https://npm.io/package/@libsql/sqlite3.md) — 39.8K weekly downloads
- [@fortemi/core](https://npm.io/package/@fortemi/core.md) — 461 weekly downloads
- [cdb-converter](https://npm.io/package/cdb-converter.md) — 341 weekly downloads
- [@uplo/adapter-prisma](https://npm.io/package/@uplo/adapter-prisma.md) — 75 weekly downloads
- [typeorm-aios](https://npm.io/package/typeorm-aios.md) — 30 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-02-23
- 1.0.1 — 2022-02-18
- 1.0.0 — 2022-02-18

## README

# Topobuf

[![Build Status](https://app.travis-ci.com/azavea/topobuf.svg?branch=main)](https://travis-ci.org/azavea/topobuf)

Topobuf is a compact binary encoding for topographic data.

Topobuf provides _lossless_[^1] compression of [TopoJSON](https://github.com/topojson/topojson) data into [protocol buffers](https://developers.google.com/protocol-buffers/).
Advantages over using JSON-based formats alone:

- **Very compact**: typically makes TopoJSON 2-3 times smaller.
- Smaller even when comparing gzipped sizes: 20-30% for TopoJSON.
- Can store topology objects too large for `JSON.stringify` / `JSON.parse`
- Can accommodate any TopoJSON data, including extensions with arbitrary properties.

#### Sample compression sizes
|                       | normal   | gzipped |
|-----------------------|----------|---------|
| pa-census-blocks.json | 280 MB   | 44 MB   |
| pa-census-blocks.pbf  | 114 MB   | 35 MB   |
| us-zips.json          | 15.02 MB | 3.19 MB |
| us-zips.pbf           | 4.85 MB  | 2.72 MB |
| idaho.json            | 1.9 MB   | 612 KB  |
| idaho.pbf             | 567 KB   | 479 KB  |


## Install

```bash
npm install topobuf
```

## API

### encode

```js
var buffer = topobuf.encode(topojson, new Pbf());
```

Given a TopoJSON object and a [Pbf](https://github.com/mapbox/pbf) object to write to,
returns a Topobuf as a `Buffer` object in Node or `UInt8Array` object in browsers.

### decode

```js
var topojson = topobuf.decode(new Pbf(data));
```

Given a [Pbf](https://github.com/mapbox/pbf) object with topobuf data, return a TopoJSON object.

## See more

This library is based on [`geobuf`](https://github.com/mapbox/geobuf) by Mapbox, which provides similar functionality for GeoJSON

[^1]: When using [quantized TopoJSON](https://github.com/topojson/topojson-client/blob/master/README.md#quantize) - _nearly lossless_ otherwise

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