Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xattr API #2415

Closed
MarkTiedemann opened this issue May 28, 2019 · 2 comments
Closed

xattr API #2415

MarkTiedemann opened this issue May 28, 2019 · 2 comments
Labels
public API related to "Deno" namespace in JS suggestion suggestions for new features (yet to be agreed)

Comments

@MarkTiedemann
Copy link
Contributor

Would love to have an API for extended file attributes.

My use case is speeding up code formatting by making it incremental: Save the last time a file was formatted in an extended file attribute, then only re-format files which were modified again after having been formatted (instead of unnecessarily re-formatting all files).

API would be along the lines of:

setFileAttr(filename: string, key: string, value: string): Promise<void>
getFileAttr(filename: string, key: string): Promise<string>

Permissions would be set -> write, get -> read.

@MarkTiedemann
Copy link
Contributor Author

On Windows, you can easily use NTFS Alternate Data Streams to store meta data on files.

function setFileAttr(filename: string, key: string, value: Uint8Array) {
  return Deno.writeFile(filename + ":" + key, value);
}

function getFileAttr(filename: string, key: string) {
  return Deno.readFile(filename + ":" + key);
}

function uint8ArrayEquals(a: Uint8Array, b: Uint8Array) {
  return a.length === b.length && a.every((val, idx) => val === b[idx]);
}

(async function test() {
  let a = new TextEncoder().encode(Date.now().toString());
  await setFileAttr(Deno.args[0], "LastTestRun", a);
  let b = await getFileAttr(Deno.args[0], "LastTestRun");
  if (!uint8ArrayEquals(a, b)) {
    console.error(a, "!==", b);
    Deno.exit(1);
  }
})();

Haven't found an easy way to do this on MacOS and Linux without native code yet.

@kitsonk kitsonk added public API related to "Deno" namespace in JS suggestion suggestions for new features (yet to be agreed) labels Nov 5, 2020
@bartlomieju
Copy link
Member

@MarkTiedemann this suggestion did not gained much traction; in an effort to reduce unwieldy number of open issues in the repo I'm going to close this one. I'd still be happy to merge a PR with implementation and tests, but this is not something core team will be working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
public API related to "Deno" namespace in JS suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

No branches or pull requests

3 participants