MCPcopy Create free account
hub / github.com/cli/cli / Read

Method Read

pkg/cmd/api/pagination.go:123–150  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

121}
122
123func (r *paginatedArrayReader) Read(p []byte) (int, error) {
124 var n int
125 var err error
126 if r.cachedByte != 0 && len(p) > 0 {
127 p[0] = r.cachedByte
128 n, err = r.Reader.Read(p[1:])
129 n += 1
130 r.cachedByte = 0
131 } else {
132 n, err = r.Reader.Read(p)
133 }
134 if !r.isSubsequentRead && !r.isFirstPage && n > 0 && p[0] == '[' {
135 if n > 1 && p[1] == ']' {
136 // empty array case
137 p[0] = ' '
138 } else {
139 // avoid starting a new array and continue with a comma instead
140 p[0] = ','
141 }
142 }
143 if !r.isLastPage && n > 0 && p[n-1] == ']' {
144 // avoid closing off an array in case we determine we are at EOF
145 r.cachedByte = p[n-1]
146 n -= 1
147 }
148 r.isSubsequentRead = true
149 return n, err
150}
151
152// jsonArrayWriter wraps a Writer which writes multiple pages of both JSON arrays
153// and objects. Call Close to write the end of the array.

Callers 1

ReadFromMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected