-
-
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
3 changed files
with
70 additions
and
0 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,26 @@ | ||
package commands | ||
|
||
import ( | ||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid" | ||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash" | ||
) | ||
|
||
type Inliner struct { | ||
base cid.Format | ||
limit int | ||
} | ||
|
||
func (p Inliner) GetCodec() uint64 { | ||
return p.base.GetCodec() | ||
} | ||
|
||
func (p Inliner) WithCodec(c uint64) cid.Format { | ||
return Inliner{p.base.WithCodec(c), p.limit} | ||
} | ||
|
||
func (p Inliner) Sum(data []byte) (*cid.Cid, error) { | ||
if len(data) > p.limit { | ||
return p.base.Sum(data) | ||
} | ||
return cid.FormatV1{Codec: p.base.GetCodec(), HashFun: 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