Documentation ¶
Overview ¶
Package fd provides types for working with file descriptors.
Index ¶
- type FD
- type ReadWriter
- func (r *ReadWriter) FD() int
- func (r *ReadWriter) Read(b []byte) (int, error)
- func (r *ReadWriter) ReadAt(b []byte, off int64) (c int, err error)
- func (r *ReadWriter) String() string
- func (r *ReadWriter) Write(b []byte) (int, error)
- func (r *ReadWriter) WriteAt(b []byte, off int64) (c int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FD ¶
type FD struct {
ReadWriter
}
FD owns a host file descriptor.
It is similar to os.File, with a few important distinctions:
FD provides a Release() method which relinquishes ownership. Like os.File, FD adds a finalizer to close the backing FD. However, the finalizer cannot be removed from os.File, forever pinning the lifetime of an FD to its os.File.
FD supports both blocking and non-blocking operation. os.File only supports blocking operation.
func NewFromFile ¶
NewFromFile creates a new FD from an os.File.
NewFromFile does not transfer ownership of the file descriptor (it will be duplicated, so both the os.File and FD will eventually need to be closed and some (but not all) changes made to the FD will be applied to the os.File as well).
The returned FD is always blocking (Go 1.9+).
func NewFromFiles ¶
NewFromFiles creates new FDs for each file in the slice.
func (*FD) Close ¶
Close closes the file descriptor contained in the FD.
Close is safe to call multiple times, but will return an error after the first call.
Concurrently calling Close and any other method is undefined.
func (*FD) File ¶
File converts the FD to an os.File.
FD does not transfer ownership of the file descriptor (it will be duplicated, so both the FD and os.File will eventually need to be closed and some (but not all) changes made to the os.File will be applied to the FD as well).
This operation is somewhat expensive, so care should be taken to minimize its use.
type ReadWriter ¶
type ReadWriter struct {
// contains filtered or unexported fields
}
ReadWriter implements io.ReadWriter, io.ReaderAt, and io.WriterAt for fd. It does not take ownership of fd.
func NewReadWriter ¶
func NewReadWriter(fd int) *ReadWriter
NewReadWriter creates a ReadWriter for fd.
func (*ReadWriter) FD ¶
func (r *ReadWriter) FD() int
FD returns the owned file descriptor. Ownership remains unchanged.
func (*ReadWriter) Read ¶
func (r *ReadWriter) Read(b []byte) (int, error)
Read implements io.Reader.
func (*ReadWriter) ReadAt ¶
func (r *ReadWriter) ReadAt(b []byte, off int64) (c int, err error)
ReadAt implements io.ReaderAt.
ReadAt always returns a non-nil error when c < len(b).
func (*ReadWriter) String ¶
func (r *ReadWriter) String() string
String implements Stringer.String().