MCPcopy Create free account
hub / github.com/denoland/std / calcFileInfo

Function calcFileInfo

http/etag.ts:79–92  ·  view source on GitHub ↗
(
  fileInfo: FileInfo,
  { algorithm = DEFAULT_ALGORITHM }: ETagOptions,
)

Source from the content-addressed store, hash-verified

77}
78
79async function calcFileInfo(
80 fileInfo: FileInfo,
81 { algorithm = DEFAULT_ALGORITHM }: ETagOptions,
82) {
83 if (fileInfo.mtime) {
84 const hash = base64Encode(
85 await crypto.subtle.digest(
86 algorithm,
87 encoder.encode(fileInfo.mtime.toJSON()),
88 ),
89 ).substring(0, 27);
90 return `${fileInfo.size.toString(16)}-${hash}`;
91 }
92}
93
94/**
95 * Calculate an ETag for string or `Uint8Array` entities. This returns a

Callers 1

eTagFunction · 0.85

Calls 3

digestMethod · 0.65
toJSONMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected