@@ -3,7 +3,6 @@ package main
3
3
import (
4
4
"errors"
5
5
"fmt"
6
- "io"
7
6
"net/http"
8
7
"net/url"
9
8
"os"
@@ -14,6 +13,7 @@ import (
14
13
"github.com/AlecAivazis/survey/v2"
15
14
"github.com/containerd/containerd/identifiers"
16
15
"github.com/lima-vm/lima/pkg/editutil"
16
+ "github.com/lima-vm/lima/pkg/ioutilx"
17
17
"github.com/lima-vm/lima/pkg/limayaml"
18
18
networks "github.com/lima-vm/lima/pkg/networks/reconcile"
19
19
"github.com/lima-vm/lima/pkg/osutil"
@@ -98,7 +98,7 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
98
98
return nil , err
99
99
}
100
100
defer resp .Body .Close ()
101
- st .yBytes , err = readAtMaximum (resp .Body , yBytesLimit )
101
+ st .yBytes , err = ioutilx . ReadAtMaximum (resp .Body , yBytesLimit )
102
102
if err != nil {
103
103
return nil , err
104
104
}
@@ -115,7 +115,7 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
115
115
return nil , err
116
116
}
117
117
defer r .Close ()
118
- st .yBytes , err = readAtMaximum (r , yBytesLimit )
118
+ st .yBytes , err = ioutilx . ReadAtMaximum (r , yBytesLimit )
119
119
if err != nil {
120
120
return nil , err
121
121
}
@@ -132,7 +132,7 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
132
132
return nil , err
133
133
}
134
134
defer r .Close ()
135
- st .yBytes , err = readAtMaximum (r , yBytesLimit )
135
+ st .yBytes , err = ioutilx . ReadAtMaximum (r , yBytesLimit )
136
136
if err != nil {
137
137
return nil , err
138
138
}
@@ -419,17 +419,3 @@ func startBashComplete(cmd *cobra.Command, args []string, toComplete string) ([]
419
419
}
420
420
return comp , cobra .ShellCompDirectiveDefault
421
421
}
422
-
423
- func readAtMaximum (r io.Reader , n int64 ) ([]byte , error ) {
424
- lr := & io.LimitedReader {
425
- R : r ,
426
- N : n ,
427
- }
428
- b , err := io .ReadAll (lr )
429
- if err != nil {
430
- if errors .Is (err , io .EOF ) && lr .N <= 0 {
431
- err = fmt .Errorf ("exceeded the limit (%d bytes): %w" , n , err )
432
- }
433
- }
434
- return b , err
435
- }
0 commit comments