File: file.go

package info (click to toggle)
golang-github-mitchellh-go-fs 0.0~git20180402.b7b9ca4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 176 kB
  • sloc: makefile: 2
file content (26 lines) | stat: -rw-r--r-- 581 bytes parent folder | download | duplicates (4)
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
package fat

type File struct {
	chain *ClusterChain
	dir   *Directory
	entry *DirectoryClusterEntry
}

func (f *File) Read(p []byte) (n int, err error) {
	return f.chain.Read(p)
}

func (f *File) Write(p []byte) (n int, err error) {
	lastByte := f.chain.writeOffset + uint32(len(p))
	if lastByte > f.entry.fileSize {
		// Increase the file size since we're writing past the end of the file
		f.entry.fileSize = lastByte

		// Write the entry out
		if err := f.dir.dirCluster.WriteToDevice(f.dir.device, f.dir.fat); err != nil {
			return 0, err
		}
	}

	return f.chain.Write(p)
}