19
19
* [ files.stat] ( #filesmkdir )
20
20
* [ files.rm] ( #filesrm )
21
21
* [ files.read] ( #filesread )
22
+ * [ files.readReadableStream] ( #filesreadreadablestream )
23
+ * [ files.readPullStream] ( #filesreadpullstream )
22
24
* [ files.write] ( #fileswrite )
23
25
* [ files.mv] ( #filesmv )
24
26
* [ files.flush] ( #filesflush )
@@ -599,8 +601,8 @@ The Mutable File System (MFS) is a virtual file system on top of IPFS that expos
599
601
600
602
Where:
601
603
602
- - ` from ` is the path of the source object to copy.
603
- - ` to ` is the path of the destination object to copy to.
604
+ - ` from ` is the path of the source file to copy.
605
+ - ` to ` is the path of the destination file to copy to.
604
606
605
607
` callback ` must follow the ` function (err) {} ` signature, where ` err ` is an Error if the operation was not successful.
606
608
@@ -700,7 +702,7 @@ ipfs.files.stat('/file.txt', (err, stats) => {
700
702
701
703
Where:
702
704
703
- - ` path ` is the path of the object to remove.
705
+ - ` path ` is the path of the file to remove.
704
706
- ` options ` is an optional Object that might contain the following keys:
705
707
- ` recursive ` is a Boolean value to decide whether or not to remove directories recursively.
706
708
@@ -728,33 +730,88 @@ ipfs.files.rm('/my/beautiful/directory', { recursive: true }, (err) => {
728
730
729
731
#### ` files.read `
730
732
731
- > Read a file.
733
+ > Read a file into a [ ` Buffer ` ] [ b ] .
732
734
733
735
##### ` Go ` ** WIP**
734
736
735
- ##### ` JavaScript ` - ipfs.files.read(path, [ options, callback] )
737
+ ##### ` JavaScript ` - ipfs.files.read(path, [ options] , [ callback] )
736
738
737
739
Where:
738
740
739
- - ` path ` is the path of the object to read.
741
+ - ` path ` is the path of the file to read.
740
742
- ` options ` is an optional Object that might contain the following keys:
741
743
- ` offset ` is an Integer with the byte offset to begin reading from.
742
744
- ` count ` is an Integer with the maximum number of bytes to read.
743
745
744
- ` callback ` must follow the ` function (err, buf) {} ` signature, where ` err ` is an Error if the operation was not successful and ` buf ` is a Buffer with the contents of ` path ` .
746
+ ` callback ` must follow the ` function (err, buf) {} ` signature, where ` err ` is an Error if the operation was not successful and ` buf ` is a [ ` Buffer ` ] [ b ] with the contents of ` path ` .
745
747
746
748
If no ` callback ` is passed, a promise is returned.
747
749
748
750
** Example:**
749
751
750
752
``` JavaScript
751
753
ipfs .files .read (' /hello-world' , (err , buf ) => {
752
- console .log (buf .toString ())
754
+ console .log (buf .toString (' utf8 ' ))
753
755
})
754
756
755
757
// Hello, World!
756
758
```
757
759
760
+ #### ` readReadableStream `
761
+
762
+ > Read a file into a [ ` ReadableStream ` ] [ rs ] .
763
+
764
+ ##### ` Go ` ** WIP**
765
+
766
+ ##### ` JavaScript ` - ipfs.files.readReadableStream(path, [ options] )
767
+
768
+ Where:
769
+
770
+ - ` path ` is the path of the file to read.
771
+ - ` options ` is an optional Object that might contain the following keys:
772
+ - ` offset ` is an Integer with the byte offset to begin reading from.
773
+ - ` count ` is an Integer with the maximum number of bytes to read.
774
+
775
+ Returns a [ ` ReadableStream ` ] [ rs ] with the contents of ` path ` .
776
+
777
+ ** Example:**
778
+
779
+ ``` JavaScript
780
+ const stream = ipfs .files .readReadableStream (' /hello-world' )
781
+ stream .on (' data' , (buf ) => console .log (buf .toString (' utf8' )))
782
+
783
+ // Hello, World!
784
+ ```
785
+
786
+ #### ` readPullStream `
787
+
788
+ > Read a file into a [ ` PullStream ` ] [ ps ] .
789
+
790
+ ##### ` Go ` ** WIP**
791
+
792
+ ##### ` JavaScript ` - ipfs.files.readPullStream(path, [ options] )
793
+
794
+ Where:
795
+
796
+ - ` path ` is the path of the file to read.
797
+ - ` options ` is an optional Object that might contain the following keys:
798
+ - ` offset ` is an Integer with the byte offset to begin reading from.
799
+ - ` count ` is an Integer with the maximum number of bytes to read.
800
+
801
+ Returns a [ ` PullStream ` ] [ ps ] with the contents of ` path ` .
802
+
803
+ ** Example:**
804
+
805
+ ``` JavaScript
806
+ pull (
807
+ ipfs .files .readPullStream (' /hello-world' ),
808
+ through (buf => console .log (buf .toString (' utf8' ))),
809
+ collect (err => {})
810
+ )
811
+
812
+ // Hello, World!
813
+ ```
814
+
758
815
#### ` files.write `
759
816
760
817
> Write to a file.
@@ -765,10 +822,13 @@ ipfs.files.read('/hello-world', (err, buf) => {
765
822
766
823
Where:
767
824
768
- - ` path ` is the path of the object to write.
825
+ - ` path ` is the path of the file to write.
769
826
- ` content ` can be:
770
- - a Buffer instance.
771
- - a Path (caveat: will only work in Node.js).
827
+ - a [ ` Buffer ` ] [ b ]
828
+ - a [ ` PullStream ` ] [ ps ]
829
+ - a [ ` ReadableStream ` ] [ rs ]
830
+ - a [ ` Blob ` ] [ blob ] (caveat: will only work in the browser)
831
+ - a string path to a file (caveat: will only work in Node.js)
772
832
- ` options ` is an optional Object that might contain the following keys:
773
833
- ` offset ` is an Integer with the byte offset to begin writing at.
774
834
- ` create ` is a Boolean to indicate to create the file if it doesn't exist.
@@ -797,8 +857,8 @@ ipfs.files.write('/hello-world', Buffer.from('Hello, world!'), (err) => {
797
857
798
858
Where:
799
859
800
- - ` from ` is the path of the source object to move.
801
- - ` to ` is the path of the destination object to move to.
860
+ - ` from ` is the path of the source file to move.
861
+ - ` to ` is the path of the destination file to move to.
802
862
803
863
` callback ` must follow the ` function (err) {} ` signature, where ` err ` is an Error if the operation was not successful.
804
864
@@ -881,3 +941,4 @@ ipfs.files.ls('/screenshots', function (err, files) {
881
941
[ rs ] : https://www.npmjs.com/package/readable-stream
882
942
[ ps ] : https://www.npmjs.com/package/pull-stream
883
943
[ cid ] : https://www.npmjs.com/package/cids
944
+ [ blob ] : https://developer.mozilla.org/en-US/docs/Web/API/Blob
0 commit comments