Skip to main content
Latest
function decode
import { decode } from "https://deno.land/x/etag@0.2.0/mod.ts";

Attempt to decode an etag into the relevant file info. This is experimental, and by design is only compatible with ETags that were either 1) generated using this module, or 2) generated with a similar library that uses the same API to generate its tags.

Examples

Example 1

// continuing the example from etag.encode

import * as etag from "https://deno.land/x/etag@0.1.1/mod.ts";
import $ from "https://deno.land/x/dax/mod.ts";

for await (const f of $.fs.expandGlob("./src/*.ts")) {
  console.log(f.name);
  const stat = Deno.statSync(f.path);

  const encoded = etag.encode(stat);
  console.log("  stat:\n\t%s", JSON.stringify(stat, null, 2));
  console.log("  eTag:\n\t%s", encoded);

  const decoded = etag.decode(encoded);
  console.log("  decoded:\n\t%s\n", JSON.stringify(decoded, null, 2));
}

Parameters

etag: string

The ETag to decode

Returns

Partial<DecodedStatTag | DecodedEntityTag> | undefined

an object of type DecodedStatTag or DecodedEntityTag, depending on which format was used to create the tag, or undefined if the decoding process was unsuccessful.