README.md 3.5 KB
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3
go-car (go!)
==================

Steven Allen's avatar
Steven Allen committed
4 5 6
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai)
[![](https://img.shields.io/badge/project-ipld-orange.svg?style=flat-square)](https://github.com/ipld/ipld)
[![](https://img.shields.io/badge/freenode-%23ipld-orange.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipld)
7
[![Go Reference](https://pkg.go.dev/badge/github.com/ipld/go-car.svg)](https://pkg.go.dev/github.com/ipld/go-car)
Steven Allen's avatar
Steven Allen committed
8
[![Coverage Status](https://codecov.io/gh/ipld/go-car/branch/master/graph/badge.svg)](https://codecov.io/gh/ipld/go-car/branch/master)
Jeromy's avatar
Jeromy committed
9

10
> A library to interact with merkledags stored as a single file
Jeromy's avatar
Jeromy committed
11

12
This is a Go implementation of the [CAR specifications](https://ipld.io/specs/transport/car/), both [CARv1](https://ipld.io/specs/transport/car/carv1/) and [CARv2](https://ipld.io/specs/transport/car/carv2/).
Jeromy's avatar
Jeromy committed
13

14
Note that there are two major module versions:
Jeromy's avatar
Jeromy committed
15

16
* [`go-car/v2`](v2/) is geared towards reading and writing CARv2 files, and also
17
  supports consuming CARv1 files and using CAR files as an IPFS blockstore.
18
* `go-car` v0, in the root directory, just supports reading and writing CARv1 files.
Jeromy's avatar
Jeromy committed
19

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
Most users should use v2, especially for new software, since the v2 API transparently supports both CAR formats.

## Features

[CARv2](v2) features:
* [Generate index](https://pkg.go.dev/github.com/ipld/go-car/v2#GenerateIndex) from an existing CARv1 file
* [Wrap](https://pkg.go.dev/github.com/ipld/go-car/v2#WrapV1) CARv1 files into a CARv2 with automatic index generation.
* Random-access to blocks in a CAR file given their CID via [Read-Only blockstore](https://pkg.go.dev/github.com/ipld/go-car/v2/blockstore#NewReadOnly) API, with transparent support for both CARv1 and CARv2
* Write CARv2 files via [Read-Write blockstore](https://pkg.go.dev/github.com/ipld/go-car/v2/blockstore#OpenReadWrite) API, with support for appending blocks to an existing CARv2 file, and resumption from a partially written CARv2 files.
* Individual access to [inner CARv1 data payload]((https://pkg.go.dev/github.com/ipld/go-car/v2#Reader.DataReader)) and [index]((https://pkg.go.dev/github.com/ipld/go-car/v2#Reader.IndexReader)) of a CARv2 file via the `Reader` API.

## Install

To install the latest version of `go-car/v2` module, run:
```shell script
go get github.com/ipld/go-car/v2
```

Alternatively, to install the v0 module, run:
```shell script
go get github.com/ipld/go-car
```

## API Documentation

See docs on [pkg.go.dev](https://pkg.go.dev/github.com/ipld/go-car).

## Examples

Here is a shortlist of other examples from the documentation

* [Wrap an existing CARv1 file into an indexed CARv2 file](https://pkg.go.dev/github.com/ipld/go-car/v2#example-WrapV1File)
* [Open read-only blockstore from a CAR file](https://pkg.go.dev/github.com/ipld/go-car/v2/blockstore#example-OpenReadOnly)
* [Open read-write blockstore from a CAR file](https://pkg.go.dev/github.com/ipld/go-car/v2/blockstore#example-OpenReadWrite)
* [Read the index from an existing CARv2 file](https://pkg.go.dev/github.com/ipld/go-car/v2/index#example-ReadFrom)
* [Extract the index from a CARv2 file and store it as a separate file](https://pkg.go.dev/github.com/ipld/go-car/v2/index#example-WriteTo)
56 57 58

## Maintainers

59 60
* [Daniel Martí](https://github.com/mvdan)
* [Masih Derkani](https://github.com/masih)
Jeromy's avatar
Jeromy committed
61 62 63 64 65

## Contribute

PRs are welcome!

66
When editing the Readme, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
Jeromy's avatar
Jeromy committed
67 68 69

## License

Steven Allen's avatar
Steven Allen committed
70
Apache-2.0/MIT © Protocol Labs