Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-cid
Commits
c1c89c20
Unverified
Commit
c1c89c20
authored
May 01, 2020
by
Whyrusleeping
Committed by
GitHub
May 01, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #102 from ipfs/feat/add-methods-for-using-less-memory
add a couple useful methods
parents
723b4ab1
628a0123
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
cid.go
cid.go
+18
-0
No files found.
cid.go
View file @
c1c89c20
...
...
@@ -25,6 +25,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"strings"
mbase
"github.com/multiformats/go-multibase"
...
...
@@ -408,6 +409,23 @@ func (c Cid) Bytes() []byte {
return
[]
byte
(c.str)
}
// ByteLen returns the length of the CID in bytes.
// It's equivalent to `len(c.Bytes())`, but works without an allocation,
// and should therefore be preferred.
//
// (See also the WriteTo method for other important operations that work without allocation.)
func
(c Cid) ByteLen()
int
{
return
len
(c.str)
}
// WriteTo writes the CID bytes to the given writer.
// This method works without incurring any allocation.
//
// (See also the ByteLen method for other important operations that work without allocation.)
func
(c Cid) WriteTo(w io.Writer) (
int
,
error
) {
return
io.WriteString(w, c.str)
}
// MarshalBinary is equivalent to Bytes(). It implements the
// encoding.BinaryMarshaler interface.
func
(c Cid) MarshalBinary() ([]
byte
,
error
) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment