Documentation
¶
Overview ¶
Package qrscan reads QR codes and barcodes from an image file through the installed qrscan command of the QR Code & Barcode Scanner engine.
The package holds no decoder. It starts the command, which you install separately, and returns its JSON report unchanged. One scan is one process. The command is started from a list of arguments, with no shell: a file name is never interpreted, whatever it holds. The package uses the standard library only, with no cgo.
scanner := qrscan.New("") // qrscan on PATH
report, err := scanner.Scan(ctx, "label.png", qrscan.Fast, qrscan.ProfileBudget)
for _, detection := range report.Detections {
fmt.Println(detection.Symbology, detection.Text)
}
Index ¶
Constants ¶
const ( // ProfileBudget keeps the profile's own budget. ProfileBudget = -1 // Unbounded sets no budget: the result then does not depend on how busy the machine is. Unbounded = 0 )
A time budget for the engine, in milliseconds.
const SupportedEngine = "0.11"
SupportedEngine is the engine line this package was checked against: every 0.11.x.
Variables ¶
var ErrBinaryNotFound = errors.New("qrscan: the qrscan command could not be started")
ErrBinaryNotFound means the qrscan command could not be started: it is not installed, not on PATH or not executable.
Functions ¶
This section is empty.
Types ¶
type Detection ¶
type Detection struct {
// Symbology is the kind of code, such as qr_code or code128.
Symbology string
// Text is the decoded text. Treat it as untrusted data: a QR code can hold any text.
Text string
// Raw is the exact bytes of the content, for content that is not text.
Raw []byte
}
Detection is one decoded content. The full entry, with its payload and measured places, is in Report.JSON.
type Profile ¶
type Profile string
Profile says how much work one scan does. The values are the ones `qrscan --profile` takes.
type Report ¶
type Report struct {
// JSON is the engine's report, exactly as printed.
JSON []byte
// ExitCode is 0 when qrscan found a code and 1 when it found none.
ExitCode int
// Detections holds one entry per distinct content.
Detections []Detection
// Score is nil when the engine made no judgment: the frame profile, or a budget that ran
// out. Nil is never zero.
Score *Score
// Complete is false when the time budget cut the scan: an empty report then proves nothing.
Complete bool
// EngineVersion is the engine that wrote the report, such as 0.11.0.
EngineVersion string
}
Report is one scan report. JSON is the text the engine printed, unchanged: nothing is renamed, rounded or recalculated. The other fields only read it. A report with no detection is a valid result, not an error.
type ScanError ¶
type ScanError struct {
// ExitCode is the command's exit code.
ExitCode int
// EngineCode is the engine's own code, such as QRS-001 for a file that is not an image.
// It is empty when the message carries none.
EngineCode string
// Message is one line of the command's own message.
Message string
}
ScanError means the engine refused the file or the options, or its output could not be read.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner starts one qrscan command. It is safe for concurrent use.
func New ¶
New returns a Scanner for the given command: a name looked up on PATH or a path. An empty name means "qrscan".
func (*Scanner) Capabilities ¶
Capabilities returns what the installed command can read, as the JSON it printed: its versions, decode engines and symbologies.
func (*Scanner) EngineVersion ¶
EngineVersion returns the version of the installed engine, such as 0.11.0. It fails with UnsupportedVersionError when that version is outside the supported line.
type Score ¶
type Score struct {
// Value is the composite score, from 0 to 100.
Value int
}
Score is the scannability judgment of a QR code.
type UnsupportedVersionError ¶
type UnsupportedVersionError struct {
// Version is what the command reported, empty when it reported none.
Version string
}
UnsupportedVersionError means the installed qrscan is not a version this package was checked against.
func (*UnsupportedVersionError) Error ¶
func (e *UnsupportedVersionError) Error() string