eTag
import { eTag } from "jsr:@ende/http";function
async function eTag(entity: string | ReturnType<TextEncoder["encode"]>, options?: ETagOptions): Promise<string>Calculate an ETag for string or Uint8Array entities. This returns a
strong tag
of the form "<ascii chars>", which guarantees the byte-for-byte equality of the resource.
You can optionally set true to the weak option to get a weak tag.
entity: string | ReturnType<TextEncoder["encode"]>The entity to get the ETag for.
options?: ETagOptionsVarious additional options.
Returns
The calculated ETag.
Example: Usage
import { eTag } from "@ende/http/etag";
import { assert } from "@ende/assert";
const body = "hello deno!";
const etag = await eTag(body);
assert(etag);
const res = new Response(body, { headers: { etag } });
function
async function eTag(entity: FileInfo, options?: ETagOptions): Promise<string | undefined>Calculate an ETag for file information entity. This returns a
weak tag
of the form W\"<ascii chars>", which guarantees the equivalence of the resource,
not the byte-for-byte equality.
entity: FileInfoThe entity to get the ETag for.
options?: ETagOptionsVarious additional options.
Returns
The calculated ETag.
Example: Usage
import { eTag } from "@ende/http/etag";
import { assert } from "@ende/assert";
const fileInfo = await Ende.stat("README.md");
const etag = await eTag(fileInfo);
assert(etag);
using file = await Ende.open("README.md");
const res = new Response(file.readable, { headers: { etag } });
function
async function eTag(entity: string | ReturnType<TextEncoder["encode"]> | FileInfo, options: ETagOptions = [UNSUPPORTED]): Promise<string | undefined>