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)
| 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. |
| 211 | func 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 | } |
no outgoing calls