file2qr

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT Imports: 10 Imported by: 1

README

file2qr

travis go report card coverage godocs

Install

To use it in your script, pull it as below and include it in your script.

go get github.com/JamesCullum/file2qr

If you want to use it as standalone client including the CLI, download the newest release for your operating system.

Usage

Basic usage
// Import at top of script
import "github.com/JamesCullum/file2qr"

// Initiate handler with default settings
handler := file2qr.New()

// Methods update this value as percentage, so that you can display it in a progressbar
current_progress := 0

// Convert `input.bin` to qr codes in the folder `frames`
// Download the newest release to get a version packaged with ffmpeg to create a video out of the frames
err := handler.Encode("./input.bin", "./frames", &current_progress)

// Convert qr codes in the folder `frames` to `output.bin`
// Download the newest release to get a version packaged with ffmpeg to extract each code frame out of a video
err := handler.Decode("./frames", "./output.bin", &current_progress)
Use as standalone converter

Download the newest release for your operationg system. It will contain a compiled CLI and packages ffmpeg for video en/decoding.

It contains shell scripts for encoding and decoding a file to qr codes and a video file of it. Execute it in a console to get further instructions.

On Windows, you can simply drag and drop the file you wish to encode or the video file you wish to decode onto the batch file. This will create a result.bin (decoding) or result.mp4 folder (encoding) in the CLI directory.

Contributing

Pull requests are welcome. Feel free to...

  • Revise documentation
  • Add new features
  • Fix bugs
  • Suggest improvements

Thanks

Thanks @scholz for the inspiration to create a simple and good Go Github project

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter struct {
	NumThread         int
	QRChunkSize       int64
	QRSideLength      int
	FilenamePadLength int
	FilePrefix        string
}

Converter is the instance of this converter. You can directly manipulate the available parameters to modify settings.

func New

func New() *Converter

New creates a converter instance with default settings.

Example
converter := New()
fmt.Println("Default threads:", converter.NumThread)

converter.NumThread = 10
fmt.Println("Modified threads:", converter.NumThread)
Output:

Default threads: 25
Modified threads: 10

func (*Converter) Decode

func (c *Converter) Decode(inputFolderpath, outputFilepath string, progress *int) error

Decode reads qr codes from a source folder, decodes them and writes the result in the destination file. The source folder should only contain images that belong to one file. It writes the current progress percentage into the provided progress reference integer.

Example
converter := New()
progress := 0
tempFolder := testDataRoot + osSep + "ExampleDecode"
tempOutput := testDataRoot + osSep + "ExampleDecode.txt"

// First encode as in the example for Encode
converter.Encode(testFile, tempFolder, &progress)

// Then decode
progress = 0
err := converter.Decode(tempFolder, tempOutput, &progress)
os.RemoveAll(tempFolder)

// Hash file
hasher := sha256.New()
f, err2 := os.Open(tempOutput)
_, err3 := io.Copy(hasher, f)
f.Close()
os.RemoveAll(tempOutput)

fmt.Println("Decoded with errors", err, err2, err3, "into file with checksum", hex.EncodeToString(hasher.Sum(nil)), "and final progress", progress)
Output:

Decoded with errors <nil> <nil> <nil> into file with checksum 603fc453b56a70b93befaaeca656a2045968d9ee74cdc7a98f3b41e3b3017169 and final progress 100

func (*Converter) Encode

func (c *Converter) Encode(inputFilepath, outputFolderpath string, progress *int) error

Encode reads the input file and converts it to QR code images in the destination folder. It writes the current progress percentage into the provided progress reference integer.

Example
converter := New()
progress := 0
tempFolder := testDataRoot + osSep + "ExampleEncode"

err := converter.Encode(testFile, tempFolder, &progress)
files, err2 := ioutil.ReadDir(tempFolder)
os.RemoveAll(tempFolder)

fmt.Println("Encoded with errors", err, err2, "into", len(files), "frames with final progress", progress)
Output:

Encoded with errors <nil> <nil> into 382 frames with final progress 100

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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