diff --git a/uuid_test.go b/uuid_test.go index c1c6001..13b2ae6 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -8,6 +8,7 @@ import ( "bytes" "errors" "fmt" + "io" "os" "runtime" "strings" @@ -884,6 +885,20 @@ func TestVersion7FromReader(t *testing.T) { } } +// NewV7FromReader returns a Version 7 UUID based on the current time and uses +// NewRandomFromReader to get bytes 8-15 of the UUID. Bytes 0-7 from the reader +// are read but are overwritten by the makeV7 function. +// On error, NewV7FromReader returns Nil and an error. +func NewV7FromReader(r io.Reader) (UUID, error) { + uuid, err := NewRandomFromReader(r) + if err != nil { + return uuid, err + } + + makeV7(uuid[:]) + return uuid, nil +} + func TestVersion7Monotonicity(t *testing.T) { length := 10000 u1 := Must(NewV7()).String() diff --git a/version7.go b/version7.go index 0f5d994..f5dee8f 100644 --- a/version7.go +++ b/version7.go @@ -4,10 +4,6 @@ package uuid -import ( - "io" -) - // UUID version 7 features a time-ordered value field derived from the widely // implemented and well known Unix Epoch timestamp source, // the number of milliseconds seconds since midnight 1 Jan 1970 UTC, leap seconds excluded. @@ -29,19 +25,6 @@ func NewV7() (UUID, error) { return uuid, nil } -// NewV7FromReader returns a Version 7 UUID based on the current time(Unix Epoch). -// it use NewRandomFromReader fill random bits. -// On error, NewV7FromReader returns Nil and an error. -func NewV7FromReader(r io.Reader) (UUID, error) { - uuid, err := NewRandomFromReader(r) - if err != nil { - return uuid, err - } - - makeV7(uuid[:]) - return uuid, nil -} - // makeV7 fill 48 bits time (uuid[0] - uuid[5]), set version b0111 (uuid[6]) // uuid[8] already has the right version number (Variant is 10) // see function NewV7 and NewV7FromReader