@@ -739,5 +739,166 @@ module.exports = (common) => {
739
739
} )
740
740
} )
741
741
} )
742
+
743
+ describe ( '.lsReadableStream' , ( ) => {
744
+ before ( ( done ) => {
745
+ const content = ( name ) => ( {
746
+ path : `test-folder/${ name } ` ,
747
+ content : directory . files [ name ]
748
+ } )
749
+
750
+ const emptyDir = ( name ) => ( { path : `test-folder/${ name } ` } )
751
+
752
+ const dirs = [
753
+ content ( 'pp.txt' ) ,
754
+ content ( 'holmes.txt' ) ,
755
+ content ( 'jungle.txt' ) ,
756
+ content ( 'alice.txt' ) ,
757
+ emptyDir ( 'empty-folder' ) ,
758
+ content ( 'files/hello.txt' ) ,
759
+ content ( 'files/ipfs.txt' ) ,
760
+ emptyDir ( 'files/empty' )
761
+ ]
762
+
763
+ ipfs . files . add ( dirs , ( err , res ) => {
764
+ expect ( err ) . to . not . exist ( )
765
+ const root = res [ res . length - 1 ]
766
+
767
+ expect ( root . path ) . to . equal ( 'test-folder' )
768
+ expect ( root . hash ) . to . equal ( directory . cid )
769
+ done ( )
770
+ } )
771
+ } )
772
+
773
+ it ( 'with a base58 encoded CID' , ( done ) => {
774
+ const cid = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
775
+ const stream = ipfs . lsReadableStream ( cid )
776
+
777
+ stream . pipe ( concat ( ( files ) => {
778
+ expect ( files ) . to . eql ( [
779
+ { depth : 1 ,
780
+ name : 'alice.txt' ,
781
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt' ,
782
+ size : 11696 ,
783
+ hash : 'QmZyUEQVuRK3XV7L9Dk26pg6RVSgaYkiSTEdnT2kZZdwoi' ,
784
+ type : 'file' } ,
785
+ { depth : 1 ,
786
+ name : 'empty-folder' ,
787
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder' ,
788
+ size : 4 ,
789
+ hash : 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' ,
790
+ type : 'dir' } ,
791
+ { depth : 1 ,
792
+ name : 'files' ,
793
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files' ,
794
+ size : 183 ,
795
+ hash : 'QmZ25UfTqXGz9RsEJFg7HUAuBcmfx5dQZDXQd2QEZ8Kj74' ,
796
+ type : 'dir' } ,
797
+ { depth : 1 ,
798
+ name : 'holmes.txt' ,
799
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt' ,
800
+ size : 582072 ,
801
+ hash : 'QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr' ,
802
+ type : 'file' } ,
803
+ { depth : 1 ,
804
+ name : 'jungle.txt' ,
805
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt' ,
806
+ size : 2305 ,
807
+ hash : 'QmT6orWioMiSqXXPGsUi71CKRRUmJ8YkuueV2DPV34E9y9' ,
808
+ type : 'file' } ,
809
+ { depth : 1 ,
810
+ name : 'pp.txt' ,
811
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt' ,
812
+ size : 4551 ,
813
+ hash : 'QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn' ,
814
+ type : 'file' }
815
+ ] )
816
+ done ( )
817
+ } ) )
818
+ } )
819
+ } )
820
+
821
+ describe ( '.lsPullStream' , ( ) => {
822
+ before ( ( done ) => {
823
+ const content = ( name ) => ( {
824
+ path : `test-folder/${ name } ` ,
825
+ content : directory . files [ name ]
826
+ } )
827
+
828
+ const emptyDir = ( name ) => ( { path : `test-folder/${ name } ` } )
829
+
830
+ const dirs = [
831
+ content ( 'pp.txt' ) ,
832
+ content ( 'holmes.txt' ) ,
833
+ content ( 'jungle.txt' ) ,
834
+ content ( 'alice.txt' ) ,
835
+ emptyDir ( 'empty-folder' ) ,
836
+ content ( 'files/hello.txt' ) ,
837
+ content ( 'files/ipfs.txt' ) ,
838
+ emptyDir ( 'files/empty' )
839
+ ]
840
+
841
+ ipfs . files . add ( dirs , ( err , res ) => {
842
+ expect ( err ) . to . not . exist ( )
843
+ const root = res [ res . length - 1 ]
844
+
845
+ expect ( root . path ) . to . equal ( 'test-folder' )
846
+ expect ( root . hash ) . to . equal ( directory . cid )
847
+ done ( )
848
+ } )
849
+ } )
850
+
851
+ it ( 'with a base58 encoded CID' , ( done ) => {
852
+ const cid = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
853
+ const stream = ipfs . lsPullStream ( cid )
854
+
855
+ pull (
856
+ stream ,
857
+ pull . collect ( ( err , files ) => {
858
+ expect ( err ) . to . not . exist ( )
859
+
860
+ expect ( files ) . to . eql ( [
861
+ { depth : 1 ,
862
+ name : 'alice.txt' ,
863
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt' ,
864
+ size : 11696 ,
865
+ hash : 'QmZyUEQVuRK3XV7L9Dk26pg6RVSgaYkiSTEdnT2kZZdwoi' ,
866
+ type : 'file' } ,
867
+ { depth : 1 ,
868
+ name : 'empty-folder' ,
869
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder' ,
870
+ size : 4 ,
871
+ hash : 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' ,
872
+ type : 'dir' } ,
873
+ { depth : 1 ,
874
+ name : 'files' ,
875
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files' ,
876
+ size : 183 ,
877
+ hash : 'QmZ25UfTqXGz9RsEJFg7HUAuBcmfx5dQZDXQd2QEZ8Kj74' ,
878
+ type : 'dir' } ,
879
+ { depth : 1 ,
880
+ name : 'holmes.txt' ,
881
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt' ,
882
+ size : 582072 ,
883
+ hash : 'QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr' ,
884
+ type : 'file' } ,
885
+ { depth : 1 ,
886
+ name : 'jungle.txt' ,
887
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt' ,
888
+ size : 2305 ,
889
+ hash : 'QmT6orWioMiSqXXPGsUi71CKRRUmJ8YkuueV2DPV34E9y9' ,
890
+ type : 'file' } ,
891
+ { depth : 1 ,
892
+ name : 'pp.txt' ,
893
+ path : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt' ,
894
+ size : 4551 ,
895
+ hash : 'QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn' ,
896
+ type : 'file' }
897
+ ] )
898
+ done ( )
899
+ } )
900
+ )
901
+ } )
902
+ } )
742
903
} )
743
904
}
0 commit comments