Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
be6d5024
Unverified
Commit
be6d5024
authored
Jun 03, 2020
by
lash
Committed by
GitHub
Jun 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add file entry implementation (#242)
parent
179fa422
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
154 additions
and
4 deletions
+154
-4
collection.go
pkg/collection/collection.go
+24
-0
entry.go
pkg/collection/entry/entry.go
+60
-0
entry_test.go
pkg/collection/entry/entry_test.go
+38
-0
metadata.go
pkg/collection/entry/metadata.go
+27
-0
io.go
pkg/file/io.go
+2
-1
kademlia_test.go
pkg/kademlia/kademlia_test.go
+1
-1
pslice_test.go
pkg/kademlia/pslice/pslice_test.go
+1
-1
helper.go
pkg/swarm/test/helper.go
+0
-0
helper_test.go
pkg/swarm/test/helper_test.go
+1
-1
No files found.
pkg/collection/collection.go
0 → 100644
View file @
be6d5024
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package collection provides high-level abstractions for collections of files
package
collection
import
(
"github.com/ethersphere/bee/pkg/swarm"
)
// Collection provides a specific ordering of a collection of binary data vectors
// stored in bee.
type
Collection
interface
{
Addresses
()
[]
swarm
.
Address
}
// Entry encapsulates data defining a single file entry.
// It may contain any number of data blobs providing context to the
// given data vector concealed by Reference.
type
Entry
interface
{
Reference
()
swarm
.
Address
Metadata
()
swarm
.
Address
}
pkg/collection/entry/entry.go
0 → 100644
View file @
be6d5024
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
entry
import
(
"errors"
"github.com/ethersphere/bee/pkg/collection"
"github.com/ethersphere/bee/pkg/swarm"
)
var
(
_
=
collection
.
Entry
(
&
Entry
{})
serializedDataSize
=
swarm
.
SectionSize
*
2
)
// Entry provides addition of metadata to a data reference.
// Implements collection.Entry.
type
Entry
struct
{
reference
swarm
.
Address
metadata
swarm
.
Address
}
// New creates a new Entry.
func
New
(
reference
,
metadata
swarm
.
Address
)
*
Entry
{
return
&
Entry
{
reference
:
reference
,
metadata
:
metadata
,
}
}
// Reference implements collection.Entry
func
(
e
*
Entry
)
Reference
()
swarm
.
Address
{
return
e
.
reference
}
// Metadata implements collection.Entry
func
(
e
*
Entry
)
Metadata
()
swarm
.
Address
{
return
e
.
metadata
}
// MarshalBinary implements encoding.BinaryMarshaler
func
(
e
*
Entry
)
MarshalBinary
()
([]
byte
,
error
)
{
br
:=
e
.
reference
.
Bytes
()
bm
:=
e
.
metadata
.
Bytes
()
b
:=
append
(
br
,
bm
...
)
return
b
,
nil
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler
func
(
e
*
Entry
)
UnmarshalBinary
(
b
[]
byte
)
error
{
if
len
(
b
)
!=
serializedDataSize
{
return
errors
.
New
(
"invalid data length"
)
}
e
.
reference
=
swarm
.
NewAddress
(
b
[
:
swarm
.
SectionSize
])
e
.
metadata
=
swarm
.
NewAddress
(
b
[
swarm
.
SectionSize
:
])
return
nil
}
pkg/collection/entry/entry_test.go
0 → 100644
View file @
be6d5024
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
entry_test
import
(
"testing"
"github.com/ethersphere/bee/pkg/collection/entry"
"github.com/ethersphere/bee/pkg/swarm/test"
)
// TestEntrySerialize verifies integrity of serialization.
func
TestEntrySerialize
(
t
*
testing
.
T
)
{
referenceAddress
:=
test
.
RandomAddress
()
metadataAddress
:=
test
.
RandomAddress
()
e
:=
entry
.
New
(
referenceAddress
,
metadataAddress
)
entrySerialized
,
err
:=
e
.
MarshalBinary
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
entryRecovered
:=
&
entry
.
Entry
{}
err
=
entryRecovered
.
UnmarshalBinary
(
entrySerialized
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
referenceAddress
.
Equal
(
entryRecovered
.
Reference
())
{
t
.
Fatalf
(
"expected reference %s, got %s"
,
referenceAddress
,
entryRecovered
.
Reference
())
}
metadataAddressRecovered
:=
entryRecovered
.
Metadata
()
if
!
metadataAddress
.
Equal
(
metadataAddressRecovered
)
{
t
.
Fatalf
(
"expected metadata %s, got %s"
,
metadataAddress
,
metadataAddressRecovered
)
}
}
pkg/collection/entry/metadata.go
0 → 100644
View file @
be6d5024
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
entry
import
(
"encoding/json"
)
// Metadata provides mime type and filename to file entry.
type
Metadata
struct
{
MimeType
string
`json:"mimetype"`
Filename
string
`json:"filename"`
}
// NewMetadata creates a new Metadata.
func
NewMetadata
(
fileName
string
)
*
Metadata
{
return
&
Metadata
{
Filename
:
fileName
,
}
}
func
(
m
*
Metadata
)
String
()
string
{
j
,
_
:=
json
.
Marshal
(
m
)
return
string
(
j
)
}
pkg/file/io.go
View file @
be6d5024
...
@@ -11,12 +11,13 @@ import (
...
@@ -11,12 +11,13 @@ import (
"io"
"io"
)
)
// simple
Joiner
ReadCloser wraps a byte slice in a io.ReadCloser implementation.
// simpleReadCloser wraps a byte slice in a io.ReadCloser implementation.
type
simpleReadCloser
struct
{
type
simpleReadCloser
struct
{
buffer
io
.
Reader
buffer
io
.
Reader
closed
bool
closed
bool
}
}
// NewSimpleReadCloser creates a new simpleReadCloser.
func
NewSimpleReadCloser
(
buffer
[]
byte
)
io
.
ReadCloser
{
func
NewSimpleReadCloser
(
buffer
[]
byte
)
io
.
ReadCloser
{
return
&
simpleReadCloser
{
return
&
simpleReadCloser
{
buffer
:
bytes
.
NewBuffer
(
buffer
),
buffer
:
bytes
.
NewBuffer
(
buffer
),
...
...
pkg/kademlia/kademlia_test.go
View file @
be6d5024
...
@@ -27,8 +27,8 @@ import (
...
@@ -27,8 +27,8 @@ import (
p2pmock
"github.com/ethersphere/bee/pkg/p2p/mock"
p2pmock
"github.com/ethersphere/bee/pkg/p2p/mock"
mockstate
"github.com/ethersphere/bee/pkg/statestore/mock"
mockstate
"github.com/ethersphere/bee/pkg/statestore/mock"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/swarm/test"
"github.com/ethersphere/bee/pkg/topology"
"github.com/ethersphere/bee/pkg/topology"
"github.com/ethersphere/bee/pkg/topology/test"
)
)
func
init
()
{
func
init
()
{
...
...
pkg/kademlia/pslice/pslice_test.go
View file @
be6d5024
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
"github.com/ethersphere/bee/pkg/kademlia/pslice"
"github.com/ethersphere/bee/pkg/kademlia/pslice"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/
topology
/test"
"github.com/ethersphere/bee/pkg/
swarm
/test"
)
)
// TestShallowestEmpty tests that ShallowestEmpty functionality works correctly.
// TestShallowestEmpty tests that ShallowestEmpty functionality works correctly.
...
...
pkg/
topology
/test/helper.go
→
pkg/
swarm
/test/helper.go
View file @
be6d5024
File moved
pkg/
topology
/test/helper_test.go
→
pkg/
swarm
/test/helper_test.go
View file @
be6d5024
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
"testing"
"testing"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/
topology
/test"
"github.com/ethersphere/bee/pkg/
swarm
/test"
)
)
// TestRandomAddressAt checks that RandomAddressAt generates a correct random address
// TestRandomAddressAt checks that RandomAddressAt generates a correct random address
...
...
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