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

Expose bytes to uuid #180

Closed
wesleytodd opened this issue Feb 17, 2017 · 10 comments
Closed

Expose bytes to uuid #180

wesleytodd opened this issue Feb 17, 2017 · 10 comments

Comments

@wesleytodd
Copy link

Do you have any interest in exposing the lib method bytesToUuid?

Usecase: I am writing two uuid's to a buffer which I am hex encoding for use in a http header, but when I decode them, I would like to store are traditional string representation in the XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX format.

It would be nice to do something like:

var buf = Buffer.from(hexEncodedString, 'hex');
var id1 = uuid.bytesToUuid(buf.slice(0, 16));
var id2 = uuid.bytesToUuid(buf.slice(17, 32));

Maybe there is another way to do this that I don't know about, so let me know if that is the case. Otherwise I can submit a PR to expose it.

@broofa
Copy link
Member

broofa commented Feb 18, 2017

No, this isn't something I expect will ever be part of the public API.

That said, require('uuid/lib/bytesToUuid') works. Just keep in mind that changes that break that will not be considered "breaking changes" from a versioning perspective.

@broofa broofa closed this as completed Feb 18, 2017
@taion
Copy link

taion commented Jun 2, 2020

Would it be possible to reconsider this? With native ES module support in Node, the "deep" import no longer works at all.

It'd be convenient to have a general-purpose way to convert a Node buffer with the bytes for a UUID into the standard hex representation, and using the bytesToUuid here seems like one of the nicer ways to do so.

As a comparison, the UUID type in the Python standard library exposes a bytes parameter when constructing a UUID that allows doing exactly this: https://docs.python.org/3/library/uuid.html#uuid.UUID.

@taion
Copy link

taion commented Jun 2, 2020

The absence of an exposed bytesToUuid method might tempt one to use uuidv4({ random: ... }), which ... can then break subtly when that function is given, say, a UUIDv5, and lead to hard-to-diagnose bugs.

@ctavan
Copy link
Member

ctavan commented Jun 2, 2020

We're currently considering to extend the API surface of this library (#455 (comment)), thank you for bringing up that use case.

We'll definitely discuss this!

@ctavan
Copy link
Member

ctavan commented Jul 22, 2020

@wesleytodd @taion we have just released uuid@8.3.0-beta.0 which includes https://github.com/uuidjs/uuid#uuidstringifyarr-offset would you mind testing it and report if that works for you?

@ctavan
Copy link
Member

ctavan commented Jul 22, 2020

Added in #479

@taion
Copy link

taion commented Jul 23, 2020

Passes our test suite. I'll deploy shortly, but I don't expect any problems. Will let you know if anything comes up, but assume it's working fine for us unless you hear otherwise.

@broofa
Copy link
Member

broofa commented Jul 27, 2020

Closing. @taion, please comment here if you have any issues and we'll reopen, or just open a new issue. Thanks for the input!

@broofa broofa closed this as completed Jul 27, 2020
@ctavan
Copy link
Member

ctavan commented Jul 27, 2020

We have just released uuid@8.3.0 which should fix this issue. Please report back if there any problems.

@taion
Copy link

taion commented Jul 27, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants