MCPcopy Create free account
hub / github.com/WICG/webpackage / WebBundleHasIntegrityBlock

Function WebBundleHasIntegrityBlock

go/integrityblock/integrityblock.go:211–227  ·  view source on GitHub ↗

WebBundleHasIntegrityBlock is a helper function that can be called with any file path to check if it has an integrtiy block. Basically this checks if the bytes fileBytes[2:10] match with the magic bytes.

(bundleFile io.ReadSeeker)

Source from the content-addressed store, hash-verified

209// WebBundleHasIntegrityBlock is a helper function that can be called with any file path to check if it has
210// an integrtiy block. Basically this checks if the bytes fileBytes[2:10] match with the magic bytes.
211func WebBundleHasIntegrityBlock(bundleFile io.ReadSeeker) (bool, error) {
212 bundleFile.Seek(2, io.SeekStart)
213
214 possibleMagic := make([]byte, len(IntegrityBlockMagic))
215 numBytesRead, err := io.ReadFull(bundleFile, possibleMagic)
216 if err != nil {
217 return false, err
218 }
219 if numBytesRead != len(IntegrityBlockMagic) {
220 return false, nil
221 }
222
223 // Return to the start of the file.
224 bundleFile.Seek(0, io.SeekStart)
225
226 return bytes.Compare(IntegrityBlockMagic, possibleMagic) == 0, nil
227}

Calls

no outgoing calls