initial commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package escpos
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/png"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SaveTicketPNG guarda el ticket en dir y devuelve la ruta del fichero.
|
||||
func SaveTicketPNG(dir string, t *Ticket) (string, error) {
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
path := filepath.Join(dir, fmt.Sprintf("ticket-%s-%04d.png", t.Time.Format("20060102-150405"), t.Seq))
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := png.Encode(f, t.Image); err != nil {
|
||||
f.Close()
|
||||
return "", err
|
||||
}
|
||||
return path, f.Close()
|
||||
}
|
||||
|
||||
// SaveCapture guarda todos los bytes recibidos en un .bin dentro de dir.
|
||||
func (p *Printer) SaveCapture(dir string) (string, int, error) {
|
||||
data := p.Capture()
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
path := filepath.Join(dir, "captura-"+time.Now().Format("20060102-150405")+".bin")
|
||||
return path, len(data), os.WriteFile(path, data, 0o644)
|
||||
}
|
||||
Reference in New Issue
Block a user