server: write tarball in 4 MiB chunks
This commit is contained in:
parent
58b6b1618d
commit
cf8959b1d7
1 changed files with 6 additions and 4 deletions
|
|
@ -166,17 +166,19 @@ func handleArtistAlbumPage(w http.ResponseWriter, req *http.Request) {
|
||||||
if musicindex.ArtistExists(artist) {
|
if musicindex.ArtistExists(artist) {
|
||||||
album, ok := musicindex.FindArtist(artist).Albums[albumName]
|
album, ok := musicindex.FindArtist(artist).Albums[albumName]
|
||||||
if ok {
|
if ok {
|
||||||
contents, err := os.ReadFile(album.Tarball)
|
f, err := os.Open(album.Tarball)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusNotFound)
|
http.Error(w, "internal server error: " + err.Error(),
|
||||||
|
http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
w.Header().Set("Content-Disposition", `attachment; filename="` +
|
w.Header().Set("Content-Disposition", `attachment; filename="` +
|
||||||
strings.ReplaceAll(album.Name, `"`, `'`) + `.tar.gz"`)
|
strings.ReplaceAll(album.Name, `"`, `'`) + `.tar.gz"`)
|
||||||
w.Header().Set("Content-Length",
|
w.Header().Set("Content-Length",
|
||||||
fmt.Sprintf("%d", album.TarballSize))
|
fmt.Sprintf("%d", album.TarballSize))
|
||||||
w.Write(contents)
|
util.DoChunks(f, 4 * 1024, func (buf []byte) { w.Write(buf) })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue