aboutsummaryrefslogtreecommitdiff
path: root/dev.go
blob: dc1c5b551ba90ea6f26056a45894d629e214483b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package robo

import (
	"bufio"
	"io"
	"os"
	"syscall"
)

type Device struct {
	io.ReadWriteCloser
}

// LP represents Line Printer
type LP struct {
	*os.File
}

func NewLP(path string) (LP, error) {
	f, err := os.OpenFile(path, os.O_RDWR, 0666)
	return LP{f}, err
}

func (d LP) Close() error {
	return d.File.Close()
}

func (d LP) SetNonblock() {
	fd := d.File.Fd()
	syscall.SetNonblock(int(fd), true)
}

func (d LP) Handle() *bufio.ReadWriter {
	r := bufio.NewReader(d.File)
	w := bufio.NewWriter(d.File)
	return bufio.NewReadWriter(r, w)
}