Skip to content

Commit e05a45d

Browse files
committed
fix: covert CRLF to LF
Signed-off-by: Shiwei Zhang <[email protected]>
1 parent 6d060be commit e05a45d

File tree

4 files changed

+321
-321
lines changed

4 files changed

+321
-321
lines changed

progress/example_test.go

+83-83
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
1-
/*
2-
Copyright The ORAS Authors.
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
6-
7-
http://www.apache.org/licenses/LICENSE-2.0
8-
9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
13-
limitations under the License.
14-
*/
15-
16-
package progress_test
17-
18-
import (
19-
"crypto/rand"
20-
"fmt"
21-
"io"
22-
23-
"oras.land/oras-go/v2/progress"
24-
)
25-
26-
// ExampleTrackReader demonstrates how to track the transmission progress of a
27-
// reader.
28-
func ExampleTrackReader() {
29-
// Set up a progress tracker.
30-
total := int64(11)
31-
tracker := progress.TrackerFunc(func(status progress.Status, err error) error {
32-
if err != nil {
33-
fmt.Printf("Error: %v\n", err)
34-
return nil
35-
}
36-
switch status.State {
37-
case progress.StateInitialized:
38-
fmt.Println("Start reading content")
39-
case progress.StateTransmitting:
40-
fmt.Printf("Progress: %d/%d bytes\n", status.Offset, total)
41-
case progress.StateTransmitted:
42-
fmt.Println("Finish reading content")
43-
default:
44-
// Ignore other states.
45-
}
46-
return nil
47-
})
48-
// Close takes no effect for TrackerFunc but should be called for general
49-
// Tracker implementations.
50-
defer tracker.Close()
51-
52-
// Wrap a reader of a random content generator with the progress tracker.
53-
r := io.LimitReader(rand.Reader, total)
54-
rc := progress.TrackReader(tracker, r)
55-
56-
// Start tracking the transmission.
57-
if err := progress.Start(tracker); err != nil {
58-
panic(err)
59-
}
60-
61-
// Read from the random content generator and discard the content, while
62-
// tracking the progress.
63-
// Note: io.Discard is wrapped with a io.MultiWriter for dropping
64-
// the io.ReadFrom interface for demonstration purposes.
65-
buf := make([]byte, 3)
66-
w := io.MultiWriter(io.Discard)
67-
if _, err := io.CopyBuffer(w, rc, buf); err != nil {
68-
panic(err)
69-
}
70-
71-
// Finish tracking the transmission.
72-
if err := progress.Done(tracker); err != nil {
73-
panic(err)
74-
}
75-
76-
// Output:
77-
// Start reading content
78-
// Progress: 3/11 bytes
79-
// Progress: 6/11 bytes
80-
// Progress: 9/11 bytes
81-
// Progress: 11/11 bytes
82-
// Finish reading content
83-
}
1+
/*
2+
Copyright The ORAS Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package progress_test
17+
18+
import (
19+
"crypto/rand"
20+
"fmt"
21+
"io"
22+
23+
"oras.land/oras-go/v2/progress"
24+
)
25+
26+
// ExampleTrackReader demonstrates how to track the transmission progress of a
27+
// reader.
28+
func ExampleTrackReader() {
29+
// Set up a progress tracker.
30+
total := int64(11)
31+
tracker := progress.TrackerFunc(func(status progress.Status, err error) error {
32+
if err != nil {
33+
fmt.Printf("Error: %v\n", err)
34+
return nil
35+
}
36+
switch status.State {
37+
case progress.StateInitialized:
38+
fmt.Println("Start reading content")
39+
case progress.StateTransmitting:
40+
fmt.Printf("Progress: %d/%d bytes\n", status.Offset, total)
41+
case progress.StateTransmitted:
42+
fmt.Println("Finish reading content")
43+
default:
44+
// Ignore other states.
45+
}
46+
return nil
47+
})
48+
// Close takes no effect for TrackerFunc but should be called for general
49+
// Tracker implementations.
50+
defer tracker.Close()
51+
52+
// Wrap a reader of a random content generator with the progress tracker.
53+
r := io.LimitReader(rand.Reader, total)
54+
rc := progress.TrackReader(tracker, r)
55+
56+
// Start tracking the transmission.
57+
if err := progress.Start(tracker); err != nil {
58+
panic(err)
59+
}
60+
61+
// Read from the random content generator and discard the content, while
62+
// tracking the progress.
63+
// Note: io.Discard is wrapped with a io.MultiWriter for dropping
64+
// the io.ReadFrom interface for demonstration purposes.
65+
buf := make([]byte, 3)
66+
w := io.MultiWriter(io.Discard)
67+
if _, err := io.CopyBuffer(w, rc, buf); err != nil {
68+
panic(err)
69+
}
70+
71+
// Finish tracking the transmission.
72+
if err := progress.Done(tracker); err != nil {
73+
panic(err)
74+
}
75+
76+
// Output:
77+
// Start reading content
78+
// Progress: 3/11 bytes
79+
// Progress: 6/11 bytes
80+
// Progress: 9/11 bytes
81+
// Progress: 11/11 bytes
82+
// Finish reading content
83+
}

progress/manager.go

+48-48
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
/*
2-
Copyright The ORAS Authors.
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
6-
7-
http://www.apache.org/licenses/LICENSE-2.0
8-
9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
13-
limitations under the License.
14-
*/
15-
16-
// Package progress tracks the status of descriptors being processed.
17-
package progress
18-
19-
import (
20-
"io"
21-
22-
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
23-
)
24-
25-
// Manager tracks the progress of multiple descriptors.
26-
type Manager interface {
27-
io.Closer
28-
29-
// Track starts tracking the progress of a descriptor.
30-
Track(desc ocispec.Descriptor) (Tracker, error)
31-
}
32-
33-
// ManagerFunc is an adapter to allow the use of ordinary functions as Managers.
34-
// If f is a function with the appropriate signature, ManagerFunc(f) is a
35-
// [Manager] that calls f.
36-
type ManagerFunc func(desc ocispec.Descriptor, status Status, err error) error
37-
38-
// Close closes the manager.
39-
func (f ManagerFunc) Close() error {
40-
return nil
41-
}
42-
43-
// Track starts tracking the progress of a descriptor.
44-
func (f ManagerFunc) Track(desc ocispec.Descriptor) (Tracker, error) {
45-
return TrackerFunc(func(status Status, err error) error {
46-
return f(desc, status, err)
47-
}), nil
48-
}
1+
/*
2+
Copyright The ORAS Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
// Package progress tracks the status of descriptors being processed.
17+
package progress
18+
19+
import (
20+
"io"
21+
22+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
23+
)
24+
25+
// Manager tracks the progress of multiple descriptors.
26+
type Manager interface {
27+
io.Closer
28+
29+
// Track starts tracking the progress of a descriptor.
30+
Track(desc ocispec.Descriptor) (Tracker, error)
31+
}
32+
33+
// ManagerFunc is an adapter to allow the use of ordinary functions as Managers.
34+
// If f is a function with the appropriate signature, ManagerFunc(f) is a
35+
// [Manager] that calls f.
36+
type ManagerFunc func(desc ocispec.Descriptor, status Status, err error) error
37+
38+
// Close closes the manager.
39+
func (f ManagerFunc) Close() error {
40+
return nil
41+
}
42+
43+
// Track starts tracking the progress of a descriptor.
44+
func (f ManagerFunc) Track(desc ocispec.Descriptor) (Tracker, error) {
45+
return TrackerFunc(func(status Status, err error) error {
46+
return f(desc, status, err)
47+
}), nil
48+
}

progress/status.go

+40-40
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
/*
2-
Copyright The ORAS Authors.
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
6-
7-
http://www.apache.org/licenses/LICENSE-2.0
8-
9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
13-
limitations under the License.
14-
*/
15-
16-
package progress
17-
18-
// State represents the state of a descriptor.
19-
type State int
20-
21-
// Registered states.
22-
const (
23-
StateUnknown State = iota // unknown state
24-
StateInitialized // progress initialized
25-
StateTransmitting // transmitting content
26-
StateTransmitted // content transmitted
27-
StateExists // content exists
28-
StateSkipped // content skipped
29-
StateMounted // content mounted
30-
)
31-
32-
// Status represents the status of a descriptor.
33-
type Status struct {
34-
// State represents the state of the descriptor.
35-
State State
36-
37-
// Offset represents the current offset of the descriptor.
38-
// Offset is discarded if set to a negative value.
39-
Offset int64
40-
}
1+
/*
2+
Copyright The ORAS Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package progress
17+
18+
// State represents the state of a descriptor.
19+
type State int
20+
21+
// Registered states.
22+
const (
23+
StateUnknown State = iota // unknown state
24+
StateInitialized // progress initialized
25+
StateTransmitting // transmitting content
26+
StateTransmitted // content transmitted
27+
StateExists // content exists
28+
StateSkipped // content skipped
29+
StateMounted // content mounted
30+
)
31+
32+
// Status represents the status of a descriptor.
33+
type Status struct {
34+
// State represents the state of the descriptor.
35+
State State
36+
37+
// Offset represents the current offset of the descriptor.
38+
// Offset is discarded if set to a negative value.
39+
Offset int64
40+
}

0 commit comments

Comments
 (0)