MCPcopy Index your code
hub / github.com/cloudfoundry/cli / zipFileHeaderLocation

Method zipFileHeaderLocation

cf/appfiles/zipper.go:202–242  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

200}
201
202func (zipper ApplicationZipper) zipFileHeaderLocation(name string) (int64, error) {
203 f, err := os.Open(name)
204 if err != nil {
205 return -1, err
206 }
207
208 defer f.Close()
209
210 // zip file header signature, 0x04034b50, reversed due to little-endian byte order
211 firstByte := byte(0x50)
212 restBytes := []byte{0x4b, 0x03, 0x04}
213 count := int64(-1)
214 foundAt := int64(-1)
215
216 reader := bufio.NewReader(f)
217
218 keepGoing := true
219 for keepGoing {
220 count++
221
222 b, err := reader.ReadByte()
223 if err != nil {
224 keepGoing = false
225 break
226 }
227
228 if b == firstByte {
229 nextBytes, err := reader.Peek(3)
230 if err != nil {
231 keepGoing = false
232 }
233 if bytes.Compare(nextBytes, restBytes) == 0 {
234 foundAt = count
235 keepGoing = false
236 break
237 }
238 }
239 }
240
241 return foundAt, nil
242}
243
244func (zipper ApplicationZipper) isZipWithOffsetFileHeaderLocation(name string) bool {
245 loc, err := zipper.zipFileHeaderLocation(name)

Callers 2

UnzipMethod · 0.95

Calls 1

CloseMethod · 0.65

Tested by

no test coverage detected