util: DoChunks: accept custom chunk sizes
This commit is contained in:
parent
f02730dc6b
commit
06f296639e
2 changed files with 3 additions and 3 deletions
|
|
@ -108,7 +108,7 @@ func serveMediaDirectory(w http.ResponseWriter, req *http.Request) {
|
||||||
http.Error(w, "not found", http.StatusNotFound)
|
http.Error(w, "not found", http.StatusNotFound)
|
||||||
return
|
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) {
|
func handleArtistAlbumPage(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,11 @@ func Dirents(dir string) (entries []string, err error) {
|
||||||
return
|
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
|
err = nil
|
||||||
bytes, chunks := int64(0), int64(0)
|
bytes, chunks := int64(0), int64(0)
|
||||||
r := bufio.NewReader(f)
|
r := bufio.NewReader(f)
|
||||||
buf := make([]byte, 0, 4*1024)
|
buf := make([]byte, 0, kib * 1024)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var n int
|
var n int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue