summaryrefslogtreecommitdiff
path: root/lib/diskio/file_os.go
blob: 2fa521d9321a5356c3ff0b6215fe33cc991ad192 (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
// Copyright (C) 2022  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package diskio

import (
	"os"
)

type OSFile[A ~int64] struct {
	*os.File
}

var _ File[assertAddr] = (*OSFile[assertAddr])(nil)

func (f *OSFile[A]) Size() A {
	fi, err := f.Stat()
	if err != nil {
		return 0
	}
	return A(fi.Size())
}

func (f *OSFile[A]) ReadAt(dat []byte, paddr A) (int, error) {
	return f.File.ReadAt(dat, int64(paddr))
}

func (f *OSFile[A]) WriteAt(dat []byte, paddr A) (int, error) {
	return f.File.WriteAt(dat, int64(paddr))
}