-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathutil.go
More file actions
46 lines (39 loc) · 720 Bytes
/
util.go
File metadata and controls
46 lines (39 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package bandwidthlimiter
func min(a, b int) int {
if a < b {
return a
}
return b
}
func min64(a, b int64) int64 {
if a < b {
return a
}
return b
}
func NewChunkIterator(buf []byte, chunkSize int) *ChunkIterator {
if buf == nil {
return nil
}
return &ChunkIterator{
buf: buf,
chunkSize: chunkSize,
offset: 0,
}
}
type ChunkIterator struct {
buf []byte
chunkSize int
offset int
}
func (i *ChunkIterator) Next() []byte {
begin := i.offset
end := min(i.offset+i.chunkSize, len(i.buf))
i.offset = end
if begin == end {
return nil
}
return i.buf[begin:end]
}