Git Product home page Git Product logo

go-ipfs-car's Introduction

go-ipfs-car

go-ipfs-car is a standalone library for packing files into a Content Addressable aRchives (CAR) file. The library can be used to generate .car file and upload the packaged data into IPFS all at once.

Features

  • Light-weight in-memory operation without bootstraping Kubo core.
  • Seamless integration with IPFS network
  • Support Car v1 and v2

Getting Started

Installation

go get -u github.com/photon-storage/go-ipfs-car

Example

Packing Car v1 format:

package main

import (
	"bytes"
	"context"
	"fmt"

	car "github.com/photon-storage/go-ipfs-car"
)

func main() {
	b := car.NewBuilder()
	v1car, err := b.Buildv1(
		context.TODO(),
		"./data",
		car.ImportOpts.CIDv1(),
	)
	if err != nil {
		fmt.Printf("Error creating car v1 builder: %v", err)
		return
	}

	v1buf := bytes.Buffer{}
	if err := v1car.Write(&v1buf); err != nil {
		fmt.Printf("Error writing out car v1 format: %v", err)
		return
	}

	fmt.Printf("Car v1 generated, CID =%v, size = %v\n", v1car.Root(), v1buf.Len())
}

Packing Car v2 format:

package main

import (
	"bytes"
	"context"
	"fmt"

	car "github.com/photon-storage/go-ipfs-car"
)

func main() {
	b := car.NewBuilder()

	ch := make(chan *car.ImportEvent, 8)
	go func() {
		for v := range ch {
			fmt.Printf("New block built, CID = %v\n", v.CID)
		}
		fmt.Printf("Done building\n")
	}()

	v2car, err := b.Buildv2(
		context.TODO(),
		"./data",
		car.ImportOpts.CIDv1(),
		car.ImportOpts.Events(ch),
	)
	if err != nil {
		fmt.Printf("Error creating car v2 builder: %v", err)
		return
	}

	v2buf := bytes.Buffer{}
	if _, err := v2car.WriteTo(&v2buf); err != nil {
		fmt.Printf("Error writing out car v2 format: %v", err)
		return
	}

	fmt.Printf("Car v2 generated, CID =%v, size = %v\n", v2car.Root(), v2buf.Len())
}

License

This project is licensed under the MIT License. See the LICENSE file for more information.

go-ipfs-car's People

Contributors

maxkaneco avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

0xgoerlimainnet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.