← Back to DAGDA | Support | Source: https://github.com/paduszym/go-cpio
Skip to content
paduszymPublic

About

Simple Go library for reading/writing CPIO archives.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-cpio

Simple Go library for reading/writing CPIO archives.

Reading

package main

import (
	"fmt"
	"github.com/paduszym/go-cpio/pkg/cpio"
	"io"
	"log"
	"os"
)

func main() {
	f, _ := os.Open("archive.cpio")
	defer f.Close()

	gr := cpio.NewReader(f)
	for {
		hdr, err := gr.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("Reading %s\n", hdr.Path)
		cnt, _ := io.ReadAll(gr)
		fmt.Println(cnt)
	}
}

Writing

package main

import (
	"github.com/paduszym/go-cpio/pkg/cpio"
	"log"
	"os"
)

func main() {
	f, _ := os.Create("archive.cpio")
	defer f.Close()

	gw := cpio.NewWriter(f)
	cnt := []byte("hello")
	hdr := &cpio.Header{Path: "file.txt", Mode: 0644, Size: uint64(len(cnt))}
	if err := gw.WriteHeader(hdr); err != nil {
		log.Fatal(err)
	}
	if _, err := gw.Write(cnt); err != nil {
		log.Fatal(err)
    }
	if err := gw.Close(); err != nil {
		log.Fatal(err)
    }
}

Credits

About

Simple Go library for reading/writing CPIO archives.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages