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

Commit fb37a9e

Browse files
committed
Improve the code
1 parent 4b4fab8 commit fb37a9e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

shell.go

+7-4
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"
@@ -358,9 +357,13 @@ func (s *Shell) FindProvs(ctx context.Context, cid string) (<-chan pstore.PeerIn
358357
defer cancel()
359358

360359
var n notif.QueryEvent
361-
scanner := bufio.NewScanner(resp.Output)
362-
for scanner.Scan() {
363-
json.Unmarshal(scanner.Bytes(), &n)
360+
decoder := json.NewDecoder(resp.Output)
361+
for {
362+
err := decoder.Decode(&n)
363+
if err != nil {
364+
return
365+
}
366+
364367
if n.Type == notif.Provider {
365368
for _, p := range n.Responses {
366369
select {

0 commit comments

Comments
 (0)