Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

serve restic: don't buffer the JSON output in memory for the list command

Nick Craig-Wood26fbd00b4f72
diff --git a/cmd/serve/restic/restic.go b/cmd/serve/restic/restic.go
index 044cc4178..0b1a170d9 100644
--- a/cmd/serve/restic/restic.go
+++ b/cmd/serve/restic/restic.go
@@ -434,17 +434,14 @@ func (s *server) listObjects(w http.ResponseWriter, r *http.Request, remote stri
}
}
- data, err := json.Marshal(ls)
+ w.Header().Set("Content-Type", "application/vnd.x.restic.rest.v2")
+ enc := json.NewEncoder(w)
+ err = enc.Encode(ls)
if err != nil {
- fs.Errorf(remote, "list marshal failed: %v", err)
+ fs.Errorf(remote, "failed to write list: %v", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
- // fs.Debugf(remote, "ls result = %s", data)
-
- w.Header().Set("Content-Type", "application/vnd.x.restic.rest.v2")
-
- _, _ = w.Write(data)
}
// createRepo creates repository directories.