From 05e314ed1fce5c69db544262d377cf8357d8d8ce Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Mon, 5 Oct 2020 12:17:07 +0200 Subject: [PATCH] Replace ioutil.ReadAll with a buffered decoder --- accounts/pkg/storage/cs3.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/accounts/pkg/storage/cs3.go b/accounts/pkg/storage/cs3.go index f642e3153..c930cba2b 100644 --- a/accounts/pkg/storage/cs3.go +++ b/accounts/pkg/storage/cs3.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "io" - "io/ioutil" "net/http" "path" "strings" @@ -93,17 +92,13 @@ func (r CS3Repo) LoadAccount(ctx context.Context, id string, a *proto.Account) ( return ¬FoundErr{"account", id} } - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - return err - } defer resp.Body.Close() - - if err := json.Unmarshal(b, &a); err != nil { + dec := json.NewDecoder(resp.Body) + var b []byte + if err = dec.Decode(&b); err != nil { return err } - - return nil + return json.Unmarshal(b, &a) } // DeleteAccount deletes an account via cs3 by id @@ -170,13 +165,12 @@ func (r CS3Repo) LoadGroup(ctx context.Context, id string, g *proto.Group) (err return ¬FoundErr{"group", id} } - b, err := ioutil.ReadAll(resp.Body) - if err != nil { + defer resp.Body.Close() + dec := json.NewDecoder(resp.Body) + var b []byte + if err = dec.Decode(&b); err != nil { return err } - - defer resp.Body.Close() - return json.Unmarshal(b, &g) }