disk

package module
v0.0.0-...-c8da316 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2022 License: MIT Imports: 5 Imported by: 10

README

go-disk

go-disk is simple disk parser, supported Master Boot Record and GUID Partition Table.

Example

package main

import (
	"fmt"
	"github.com/masahiro331/go-disk"
	"io"
	"log"
	"os"
)

func main() {
	if len(os.Args) != 2 {
		log.Fatal("arguments error, './main ${file}'")
	}
	f, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	fi, err := f.Stat()
	if err != nil {
		log.Fatal(err)
	}
	r := io.NewSectionReader(f, 0, fi.Size())
	driver, err := disk.NewDriver(r)
	if err != nil {
		log.Fatal(err)
	}

	count := 0
	for {
		p, err := driver.Next()
		if err != nil {
			if err == io.EOF {
				return
			}
			log.Fatal(p.Name(), err)
		}
		log.Println(p.GetSize())
		f, err = os.Create(fmt.Sprintf("%s%d", p.Name(), count))
		if err != nil {
			log.Fatal(err)
		}
		io.Copy(f, p)
		count++
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver interface {
	Next() (types.Partition, error)
}

func NewDriver

func NewDriver(sr *io.SectionReader) (Driver, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL