Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 5627dd9

Browse files
committed
Improve the code
1 parent da9d6e3 commit 5627dd9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

shell.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package shell
33

44
import (
5-
"bufio"
65
"bytes"
76
"context"
87
"encoding/json"
@@ -393,9 +392,13 @@ func (s *Shell) FindProvs(ctx context.Context, cid string) (<-chan pstore.PeerIn
393392
defer cancel()
394393

395394
var n notif.QueryEvent
396-
scanner := bufio.NewScanner(resp.Output)
397-
for scanner.Scan() {
398-
json.Unmarshal(scanner.Bytes(), &n)
395+
decoder := json.NewDecoder(resp.Output)
396+
for {
397+
err := decoder.Decode(&n)
398+
if err != nil {
399+
return
400+
}
401+
399402
if n.Type == notif.Provider {
400403
for _, p := range n.Responses {
401404
select {

0 commit comments

Comments
 (0)