fmtbytes

package module
v0.0.0-...-8bc3fe2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2018 License: MIT Imports: 5 Imported by: 31

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFileLength

func GetFileLength(file *os.File) int64

GetFileLength gets the full size in bytes of the file given

func ParsePascalString

func ParsePascalString(file *os.File) string

ParsePascalString parses a pascal string directly from file

func ParseUnicodeString

func ParseUnicodeString(file *os.File) string

ParseUnicodeString parses a unicode string from the photoshop file into a string

func ReadBytesLong

func ReadBytesLong(file *os.File) uint32

ReadBytesLong reads 4 bytes into a new buffer and returns the result as a uint32

func ReadBytesLongLong

func ReadBytesLongLong(file *os.File) uint64

ReadBytesLongLong reads 8 bytes into a new buffer and returns the result as a uint64

func ReadBytesNInt

func ReadBytesNInt(file *os.File, length uint32) []byte

ReadBytesNInt reads length bytes into a new buffer and returns the result as a []byte

func ReadBytesShort

func ReadBytesShort(file *os.File) uint16

ReadBytesShort reads 2 bytes into a new buffer and returns the result as an uint16

func ReadBytesString

func ReadBytesString(file *os.File, length int) string

ReadBytesString reads length number of bytes into a new buffer and returns the result as a string

func ReadDouble

func ReadDouble(file *os.File) (float64, error)

ReadDouble reads a 64bit int

func ReadFloat

func ReadFloat(file *os.File) float32

ReadFloat reads 4bytes into a float

func ReadIntoArray16

func ReadIntoArray16(file *os.File, length uint32) []uint16

ReadIntoArray16 takes a []byte and creates a new slice containing the values in uint16 form

func ReadIntoArray8

func ReadIntoArray8(file *os.File, length uint32) []uint8

ReadIntoArray8 takes a []byte and creates a new slice containing the values in uint8 form

func ReadRawBytes

func ReadRawBytes(file *os.File, length int) []byte

ReadRawBytes returns a buffer containing length bytes at the current file pointer index

func ReadSingleByte

func ReadSingleByte(file *os.File) int

ReadSingleByte reads 1 bytes into a new buffer and returns the result as an uint16

Types

This section is empty.

Jump to

Keyboard shortcuts

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