pisdhooy / fmtbytes

util that makes reading files a lot easier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fmtbytes GoDoc

A package that makes it easier to read structured bytes from a file.

Installation

$ go get github.com/pisdhooy/fmtbytes

basic Example

This example shows how fmtbytes can be used to confirm that a .png file is actually in the .png format.

package main

import (
  "fmt"
  
  "github.com/pisdhooy/fmtbytes"
)

func main() {
  file, err := os.Open("path/to/some.file.png");
  if err != nil {
    panic(err)
  }
  
  highBit := fmtbytes.ReadSingleByte(file);
  if highBit != 89 {
    panic("high bit invalid")
  }
  
  signature := fmtbytes.ReadBytesString(file, 3)
  if signature != "PNG" {
    panic("file signature is invalid")
  }
}

About

util that makes reading files a lot easier

License:MIT License


Languages

Language:Go 100.0%