25 lines
891 B
Kotlin
25 lines
891 B
Kotlin
package ziputils
|
|
|
|
import java.nio.ByteBuffer
|
|
import java.nio.ByteOrder
|
|
|
|
internal class EndOfCentralDirectoryLocator(
|
|
val endOfCentralDirectory64Offset: ULong
|
|
) {
|
|
companion object {
|
|
const val SIGNATURE = 0x07064b50U
|
|
const val SIZE = 20
|
|
@Throws(InvalidDataException::class)
|
|
fun fromByteArray(data: ByteArray, offset: Int): EndOfCentralDirectoryLocator {
|
|
if (data.size - offset < SIZE) {
|
|
throw InvalidDataException("EOCD64 locator must be at least 20 bytes")
|
|
}
|
|
val buf = ByteBuffer.wrap(data, offset, SIZE).order(ByteOrder.LITTLE_ENDIAN)
|
|
if (buf.getInt().toUInt() != SIGNATURE) {
|
|
throw InvalidSignatureException("Invalid signature")
|
|
}
|
|
buf.position(offset + 8)
|
|
return EndOfCentralDirectoryLocator(buf.getLong().toULong())
|
|
}
|
|
}
|
|
} |