util: DoChunks: accept custom chunk sizes

This commit is contained in:
Jeremy Baxter 2026-01-05 01:23:47 +13:00
parent f02730dc6b
commit 06f296639e
2 changed files with 3 additions and 3 deletions

View file

@ -108,7 +108,7 @@ func serveMediaDirectory(w http.ResponseWriter, req *http.Request) {
http.Error(w, "not found", http.StatusNotFound)
return
}
util.DoChunks(f, func (buf []byte) { w.Write(buf) })
util.DoChunks(f, 4, func (buf []byte) { w.Write(buf) })
}
func handleArtistAlbumPage(w http.ResponseWriter, req *http.Request) {

View file

@ -39,11 +39,11 @@ func Dirents(dir string) (entries []string, err error) {
return
}
func DoChunks(f io.Reader, fun func (buf []byte)) (err error) {
func DoChunks(f io.Reader, kib uint, fun func (buf []byte)) (err error) {
err = nil
bytes, chunks := int64(0), int64(0)
r := bufio.NewReader(f)
buf := make([]byte, 0, 4*1024)
buf := make([]byte, 0, kib * 1024)
for {
var n int