Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 795 Bytes

README.md

File metadata and controls

39 lines (29 loc) · 795 Bytes

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")
  }
}