Ejemplo n.º 1
0
// Write the bytes in buf to the file. Returns the number of bytes written and
// an error, if any.
func (f *File) Write(buf []byte) (n int, err error) {
	if f.isdir() {
		return 0, syscall.EISDIR
	}

	n = int(C.PHYSFS_write(f.cfile, unsafe.Pointer(&buf[0]), 1, C.PHYSFS_uint32(len(buf))))

	if n == -1 {
		return n, errors.New(GetLastError())
	}

	return n, nil
}
Ejemplo n.º 2
0
// Read up to len(buf) bytes from the file into buf. Returns the number of bytes
// read and an error, if any.
func (f *File) Read(buf []byte) (n int, err error) {
	if f.isdir() {
		return 0, syscall.EISDIR
	}

	n = int(C.PHYSFS_read(f.cfile, unsafe.Pointer(&buf[0]), 1, C.PHYSFS_uint32(len(buf))))

	if n == -1 {
		err = errors.New(GetLastError())
	}

	if f.EOF() {
		err = io.EOF
	}

	return n, err
}