qrFile

package module
v0.0.0-...-81c5aec Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2015 License: MIT Imports: 15 Imported by: 0

README

qrFile

qrFile provides operations to convert a file to a set of QR code images and eventually restore this file from the image set. The functionality is contained in the qrFile package. Reading QR Codes is realized using zbar (http://zbar.sourceforge.net/) for parsing.

Sample implementation

A small command line tool is included in the example folder.

Command line args for qrFileApp
-imageDirectory string
    Directory where resulting image files (default "./img_dir")
-imagePrefix string
    Prefix of the resulting images in input mode. (default "img_")
-in string
    File to be converted in input mode. Providing an input file selects input mode.
-interactive
    If this is set, a small http server is started; the site provides a rudimentary interface to convert a file to QR images and display them.
-out string
    File to store the extracted data to. (default "result")
-outputDirectory string
    Directory where result files are stored. (default "./output_dir")
-port int
    Http port for the web server. (default 8080)

If provided with the --in parameter, qrFileApp converts the file provided into a set of png images containing the file contents encoded in QR images.

go run qrFileApp.go --in ~/test.txt

If no named arguments are provided, qrFileApp reads the argument list as a file list containing images. It then tries to restore the contained data, writing the results into the default folder (./output_dir) using the default filename (result).

go run qrFileApp.go img_dir/*

The tool can be started with the --interactive flag (and, optionally, a --port flag). If so, a very rudimentary web server is started which provides an interface to encode a file and display the resulting data.

go run qrFileApp.go --interactive

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QrElement

type QrElement struct {
	Index         uint64
	MaxIndex      uint64
	PayloadLength uint64 // nescessary to store this since we will pad up to max length
	Payload       string
}

QrElement describes the data stored inside a single QR image

func GetElement

func GetElement(idx uint64, maxidx uint64, payload string) (elem QrElement, err error)

GetElement creates a single QrElement

func (*QrElement) AsQR

func (elem *QrElement) AsQR() (*qr.Code, error)

AsQR creates a qr instance containing the data stored in the QrElement

func (*QrElement) AsString

func (elem *QrElement) AsString() string

AsString formats a QrElement for printing

func (*QrElement) ParsePNG

func (elem *QrElement) ParsePNG(fname string) error

ParsePNG parses a png image. This makes use of zbarimg from the zbar suite (http://zbar.sourceforge.net/) for parsing.

func (*QrElement) ParseString

func (elem *QrElement) ParseString(str string) (err error)

ParseString is used during conversion from a parsed QR code. This parses the string contents & stores them in the QrElement.

type QrElements

type QrElements struct {
	Elements []QrElement
}

QrElements is a collection of QrElement entries; provides global methods such as QR creation etc. Implements sort.Interface

func GetElements

func GetElements(payload string) (elements *QrElements, err error)

GetElements creates a number of elements from a given string to be stored (usually a hex-encoded string containing the data of a given file)

func MakeQrElements

func MakeQrElements(elementCount uint64) *QrElements

MakeQrElements prepares the data structure QrElements with a pre-defined element count. Used in GetElements.

func (*QrElements) FromPNGs

func (elem *QrElements) FromPNGs(files []string) error

FromPNGs reads a set of png files & stores their contents in a set of QrElement structs. Also provides basic sanity tests (complete set, no duplicates etc...). The file list may contain wildcards (each entry is parsed using filepath.Glob)

func (*QrElements) Len

func (elements *QrElements) Len() int

func (*QrElements) Less

func (elements *QrElements) Less(i, j int) bool

func (*QrElements) StoreData

func (elem *QrElements) StoreData(fileObject *QrFile) error

StoreData writes the data stored in all QrElement structs in a provided QrFile object. The QrFile object then is used to write the contents to disc.

func (*QrElements) Swap

func (elements *QrElements) Swap(i, j int)

func (*QrElements) WritePNGs

func (elem *QrElements) WritePNGs(workPath string, fnamePrefix string) error

WritePNGs creates a set of PNG images; one for each QrElement stored. Each element spawns a go routine.

type QrFile

type QrFile struct {
	Fname string
	Data  []byte
}

Data types QrFile provides means to read and write the input or output files (not the PNGs, though) zbar (http://zbar.sourceforge.net/) ist used for reading/interpreting qr code images. zbarimg needs to be available in PATH

func FromFile

func FromFile(fname string) (*QrFile, error)

FromFile creates a QrFile instance and reads the files contents

func New

func New() *QrFile

Constructor for a QrFile instance

func (*QrFile) ReadFile

func (qrf *QrFile) ReadFile() (err error)

ReadFile reads the file defined by Fname (in binary mode) and stores in in the internal buffer

func (*QrFile) ToFile

func (qrf *QrFile) ToFile() (err error)

ToFile stores the data contained in the QrFile instance to a file (filename stored in QrFile instance as well)

func (*QrFile) ToHexString

func (qrf *QrFile) ToHexString() (str string)

ToHexString provides the file contents encoded in a hex string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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