first commit

This commit is contained in:
2026-06-19 12:32:14 +09:00
commit eb8d9b9460
36 changed files with 6502 additions and 0 deletions

27
httpdl/alloc_linux.go Normal file
View File

@@ -0,0 +1,27 @@
//go:build linux
package httpdl
import (
"os"
"golang.org/x/sys/unix"
)
// allocate reserves disk space for the output file according to the
// --file-allocation mode: none does nothing (sparse), trunc sets the size,
// prealloc/falloc reserve real blocks with fallocate (falling back to a plain
// truncate if the filesystem does not support it).
func allocate(f *os.File, mode string, size int64) error {
switch mode {
case "none":
return nil
case "trunc":
return f.Truncate(size)
default: // prealloc, falloc
if err := unix.Fallocate(int(f.Fd()), 0, 0, size); err != nil {
return f.Truncate(size)
}
return nil
}
}