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

Strongly-typed extended attribute names #1

Open
sindresorhus opened this issue Mar 10, 2024 · 0 comments
Open

Strongly-typed extended attribute names #1

sindresorhus opened this issue Mar 10, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sindresorhus
Copy link
Owner

sindresorhus commented Mar 10, 2024

It would be useful to be able to define strongly-typed keys that know how to decode/encode the value.

import ExtendedAttributes

extension ExtendedAttributes.Name {
	static let isProtected = Self(
		get: { api in
			try api.getPropertyListSerializedValue("com.apple.rootless", type: Bool.self) ?? false
		},
		set: { api, value, flags in
			try api.setPropertyListSerializedValue("com.apple.rootless", value: value, flags: flags)
		}
	)
}

let fileURL = URL(fileURLWithPath: "/path/to/file")
let isProtected = try? fileURL.extendedAttributes.get(.isProtected)

We could even include some common ones.


Feedback wanted

@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Mar 10, 2024
@sindresorhus sindresorhus changed the title Strongly-typed names Strongly-typed extended attribute names Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant