-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for inlining via the id-hash to the add command.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
- Loading branch information
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package commands | ||
|
||
import ( | ||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash" | ||
cid "gx/ipfs/Qmdu2AYUV7yMoVBQPxXNfe7FJcdx16kYtsx6jAPKWQYF1y/go-cid" | ||
) | ||
|
||
// Inliner is a cid.Builder that will use the id multihash when the | ||
// size of the content is no more than limit | ||
type Inliner struct { | ||
base cid.Builder | ||
limit int | ||
} | ||
|
||
// GetCodec implements the cid.Builder interface | ||
func (p Inliner) GetCodec() uint64 { | ||
return p.base.GetCodec() | ||
} | ||
|
||
// WithCodec implements the cid.Builder interface | ||
func (p Inliner) WithCodec(c uint64) cid.Builder { | ||
return Inliner{p.base.WithCodec(c), p.limit} | ||
} | ||
|
||
// Sum implements the cid.Builder interface | ||
func (p Inliner) Sum(data []byte) (*cid.Cid, error) { | ||
if len(data) > p.limit { | ||
return p.base.Sum(data) | ||
} | ||
return cid.V1Builder{Codec: p.base.GetCodec(), MhType: mh.ID}.Sum(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters