Ejemplo n.º 1
0
func (mFile *mmapFileImpl) Read(data []byte) (int, error) {
	start := _HeaderSize + mFile.pos
	end := math.MinInt(mFile.mapSize, start+len(data))

	length := end - start

	if end > mFile.mapSize {
		return 0, errors.New("Tried to read beyond end of file")
	}

	if length > _MaxFileSize {
		log.Fatal("File too large")
	}

	check := copy(data, mFile.memmap[start:])

	if check != length {
		log.Fatal("Could not read entire length")
	}

	// Moved on
	mFile.pos = end

	return length, nil
}
Ejemplo n.º 2
0
func (mFile *mmapFileImpl) Seek(pos int, from fs.FileOffset) {
	switch from {
	case fs.Beginning:
		mFile.pos = pos
	case fs.Current:
		mFile.pos = pos + pos
	case fs.End:
		mFile.pos = mFile.mapSize - pos
	}
	mFile.pos = math.MaxInt(0, math.MinInt(mFile.pos, mFile.mapSize-1))
}