@@ -3,8 +3,8 @@ use std::io;
33use std:: sync:: { Arc , Mutex } ;
44
55use bao_tree:: io:: fsm:: Outboard ;
6- use bao_tree:: io:: outboard:: PreOrderMemOutboard ;
7- use bao_tree:: { BaoTree , ByteNum } ;
6+ use bao_tree:: io:: outboard:: { PostOrderMemOutboard , PreOrderMemOutboard } ;
7+ use bao_tree:: BaoTree ;
88use bytes:: Bytes ;
99use iroh:: bytes:: store:: bao_tree:: blake3;
1010use iroh:: bytes:: store:: { BaoBlobSize , MapEntry } ;
@@ -24,11 +24,17 @@ struct Inner {
2424impl S3Store {
2525 pub async fn import_mem ( & self , data : Bytes ) -> anyhow:: Result < Hash > {
2626 let size = data. as_ref ( ) . len ( ) as u64 ;
27- let ( mut outboard, hash) = bao_tree:: io:: outboard ( & data, IROH_BLOCK_SIZE ) ;
28- outboard. splice ( 0 ..8 , [ ] ) ;
29- let tree = BaoTree :: new ( ByteNum ( size) , IROH_BLOCK_SIZE ) ;
30- let outboard = PreOrderMemOutboard :: new ( hash, tree, outboard. into ( ) )
31- . map_err ( |e| anyhow:: anyhow!( "outboard creation fail {}" , e) ) ?;
27+ let ( outboard, hash) = {
28+ let outboard = PostOrderMemOutboard :: create ( & data, IROH_BLOCK_SIZE ) . flip ( ) ;
29+ let hash = outboard. root ;
30+ ( outboard. data , hash)
31+ } ;
32+ let tree = BaoTree :: new ( size, IROH_BLOCK_SIZE ) ;
33+ let outboard = PreOrderMemOutboard {
34+ root : hash,
35+ tree,
36+ data : outboard. into ( ) ,
37+ } ;
3238 let mut state = self . 0 . entries . lock ( ) . unwrap ( ) ;
3339 state. insert (
3440 hash,
@@ -41,11 +47,17 @@ impl S3Store {
4147 let mut http_adapter = HttpAdapter :: new ( url. clone ( ) ) ;
4248 let data = http_adapter. read_to_end ( ) . await ?;
4349 let size = data. len ( ) as u64 ;
44- let ( mut outboard, hash) = bao_tree:: io:: outboard ( data, IROH_BLOCK_SIZE ) ;
45- outboard. splice ( 0 ..8 , [ ] ) ;
46- let tree = BaoTree :: new ( ByteNum ( size) , IROH_BLOCK_SIZE ) ;
47- let outboard = PreOrderMemOutboard :: new ( hash, tree, outboard. into ( ) )
48- . map_err ( |e| anyhow:: anyhow!( "outboard creation fail {}" , e) ) ?;
50+ let ( outboard, hash) = {
51+ let outboard = PostOrderMemOutboard :: create ( data, IROH_BLOCK_SIZE ) . flip ( ) ;
52+ let hash = outboard. root ;
53+ ( outboard. data , hash)
54+ } ;
55+ let tree = BaoTree :: new ( size, IROH_BLOCK_SIZE ) ;
56+ let outboard = PreOrderMemOutboard {
57+ root : hash,
58+ tree,
59+ data : outboard. into ( ) ,
60+ } ;
4961 let mut state = self . 0 . entries . lock ( ) . unwrap ( ) ;
5062 state. insert (
5163 hash,
@@ -133,10 +145,10 @@ impl AsyncSliceReader for File {
133145 }
134146 }
135147
136- async fn len ( & mut self ) -> io:: Result < u64 > {
148+ async fn size ( & mut self ) -> io:: Result < u64 > {
137149 match self {
138- Self :: S3 ( s3) => s3. len ( ) . await ,
139- Self :: Inline ( bytes) => bytes. len ( ) . await ,
150+ Self :: S3 ( s3) => s3. size ( ) . await ,
151+ Self :: Inline ( bytes) => bytes. size ( ) . await ,
140152 }
141153 }
142154}
0 commit comments