MCPcopy Create free account
hub / github.com/Effect-TS/effect / validate

Function validate

packages/effect/src/encoding/Zip.ts:896–923  ·  view source on GitHub ↗
(header: Header)

Source from the content-addressed store, hash-verified

894}
895
896const validate = (header: Header): void => {
897 const { method, mode, mtime, path, size, type } = header
898 if (path === "") throw invalidHeader("path is empty")
899 const quoted = JSON.stringify(path)
900 if (path.startsWith("/")) throw invalidHeader(`path ${quoted} is absolute`)
901 // The zip format forbids these, and libarchive reads them as separators and roots
902 if (path.includes("\\")) throw invalidHeader(`path ${quoted} contains a backslash`)
903 if (/^[A-Za-z]:/.test(path)) throw invalidHeader(`path ${quoted} starts with a drive letter`)
904 if (path.includes("\0")) throw invalidHeader(`path ${quoted} contains a NUL character`)
905 if (type === "File") {
906 if (path.endsWith("/")) throw invalidHeader(`file path ${quoted} ends with "/"`)
907 if (method !== "Store" && method !== "Deflate") throw invalidHeader(`unknown method for ${quoted}`)
908 } else if (type === "Directory") {
909 if (!path.endsWith("/")) throw invalidHeader(`directory path ${quoted} does not end with "/"`)
910 if (size !== undefined && size !== 0) throw invalidHeader(`directory ${quoted} has a size`)
911 } else {
912 throw invalidHeader(`unknown entry type for ${quoted}`)
913 }
914 if (size !== undefined && !(Number.isSafeInteger(size) && size >= 0)) {
915 throw invalidHeader(`size of ${quoted} is not a non-negative safe integer`)
916 }
917 if (mode !== undefined && !(Number.isInteger(mode) && mode >= 0 && mode <= 0o7777)) {
918 throw invalidHeader(`mode of ${quoted} is not a permission mode`)
919 }
920 if (Number.isNaN(mtime.getTime())) {
921 throw invalidHeader(`mtime of ${quoted} is not a valid date`)
922 }
923}
924
925interface EntryRecord {
926 readonly name: Uint8Array

Callers 2

encodeFunction · 0.70
encoderFunction · 0.70

Calls 2

getTimeMethod · 0.80
invalidHeaderFunction · 0.70

Tested by

no test coverage detected