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-block-format
Commits
1e01b02f
Commit
1e01b02f
authored
May 05, 2016
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename blocks.RawBlock to blocks.BasicBlock.
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
parent
92cc3f1e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
blocks.go
blocks.go
+10
-10
No files found.
blocks.go
View file @
1e01b02f
...
@@ -20,47 +20,47 @@ type Block interface {
...
@@ -20,47 +20,47 @@ type Block interface {
}
}
// Block is a singular block of data in ipfs
// Block is a singular block of data in ipfs
type
Raw
Block
struct
{
type
Basic
Block
struct
{
multihash
mh
.
Multihash
multihash
mh
.
Multihash
data
[]
byte
data
[]
byte
}
}
// NewBlock creates a Block object from opaque data. It will hash the data.
// NewBlock creates a Block object from opaque data. It will hash the data.
func
NewBlock
(
data
[]
byte
)
*
Raw
Block
{
func
NewBlock
(
data
[]
byte
)
*
Basic
Block
{
return
&
Raw
Block
{
data
:
data
,
multihash
:
u
.
Hash
(
data
)}
return
&
Basic
Block
{
data
:
data
,
multihash
:
u
.
Hash
(
data
)}
}
}
// NewBlockWithHash creates a new block when the hash of the data
// NewBlockWithHash creates a new block when the hash of the data
// is already known, this is used to save time in situations where
// is already known, this is used to save time in situations where
// we are able to be confident that the data is correct
// we are able to be confident that the data is correct
func
NewBlockWithHash
(
data
[]
byte
,
h
mh
.
Multihash
)
(
*
Raw
Block
,
error
)
{
func
NewBlockWithHash
(
data
[]
byte
,
h
mh
.
Multihash
)
(
*
Basic
Block
,
error
)
{
if
u
.
Debug
{
if
u
.
Debug
{
chk
:=
u
.
Hash
(
data
)
chk
:=
u
.
Hash
(
data
)
if
string
(
chk
)
!=
string
(
h
)
{
if
string
(
chk
)
!=
string
(
h
)
{
return
nil
,
errors
.
New
(
"Data did not match given hash!"
)
return
nil
,
errors
.
New
(
"Data did not match given hash!"
)
}
}
}
}
return
&
Raw
Block
{
data
:
data
,
multihash
:
h
},
nil
return
&
Basic
Block
{
data
:
data
,
multihash
:
h
},
nil
}
}
func
(
b
*
Raw
Block
)
Multihash
()
mh
.
Multihash
{
func
(
b
*
Basic
Block
)
Multihash
()
mh
.
Multihash
{
return
b
.
multihash
return
b
.
multihash
}
}
func
(
b
*
Raw
Block
)
Data
()
[]
byte
{
func
(
b
*
Basic
Block
)
Data
()
[]
byte
{
return
b
.
data
return
b
.
data
}
}
// Key returns the block's Multihash as a Key value.
// Key returns the block's Multihash as a Key value.
func
(
b
*
Raw
Block
)
Key
()
key
.
Key
{
func
(
b
*
Basic
Block
)
Key
()
key
.
Key
{
return
key
.
Key
(
b
.
multihash
)
return
key
.
Key
(
b
.
multihash
)
}
}
func
(
b
*
Raw
Block
)
String
()
string
{
func
(
b
*
Basic
Block
)
String
()
string
{
return
fmt
.
Sprintf
(
"[Block %s]"
,
b
.
Key
())
return
fmt
.
Sprintf
(
"[Block %s]"
,
b
.
Key
())
}
}
func
(
b
*
Raw
Block
)
Loggable
()
map
[
string
]
interface
{}
{
func
(
b
*
Basic
Block
)
Loggable
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
return
map
[
string
]
interface
{}{
"block"
:
b
.
Key
()
.
String
(),
"block"
:
b
.
Key
()
.
String
(),
}
}
...
...
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