@@ -662,6 +662,13 @@ public String chcid(String path) throws IOException {
662
662
return retrieveString("files/chcid?args=" + arg);
663
663
}
664
664
665
+ public String chcid(String path, Optional<Integer> cidVersion, Optional<String> hash) throws IOException {
666
+ String arg = URLEncoder.encode(path, "UTF-8");
667
+ String cid = cidVersion.isPresent() ? "&cid-version=" + cidVersion.get() : "";
668
+ String hashFunc = hash.isPresent() ? "&hash=" + hash.get() : "";
669
+ return retrieveString("files/chcid?args=" + arg + cid + hashFunc);
670
+ }
671
+
665
672
public String cp(String source, String dest, boolean parents) throws IOException {
666
673
return retrieveString("files/cp?arg=" + URLEncoder.encode(source, "UTF-8") + "&arg=" +
667
674
URLEncoder.encode(dest, "UTF-8") + "&parents=" + parents);
@@ -695,10 +702,11 @@ public String mkdir(String path, boolean parents) throws IOException {
695
702
return retrieveString("files/mkdir?arg=" + arg + "&parents=" + parents);
696
703
}
697
704
698
- public String mkdir(String path, boolean parents, int cidVersion, Multihash hash) throws IOException {
705
+ public String mkdir(String path, boolean parents, Optional<Integer> cidVersion, Optional<String> hash) throws IOException {
699
706
String arg = URLEncoder.encode(path, "UTF-8");
700
- return retrieveString("files/mkdir?arg=" + arg + "&parents=" + parents + "&cid-version=" +
701
- cidVersion + "&hash=" + hash);
707
+ String cid = cidVersion.isPresent() ? "&cid-version=" + cidVersion.get() : "";
708
+ String hashFunc = hash.isPresent() ? "&hash=" + hash.get() : "";
709
+ return retrieveString("files/mkdir?arg=" + arg + "&parents=" + parents + cid + hashFunc);
702
710
}
703
711
704
712
public String mv(String source, String dest) throws IOException {
@@ -725,7 +733,11 @@ public Map stat(String path) throws IOException {
725
733
String arg = URLEncoder.encode(path, "UTF-8");
726
734
return retrieveMap("files/stat?arg=" + arg);
727
735
}
728
-
736
+ public Map stat(String path, Optional<String> format, boolean withLocal) throws IOException {
737
+ String arg = URLEncoder.encode(path, "UTF-8");
738
+ String formatStr = format.isPresent() ? "&format=" + format.get() : "";
739
+ return retrieveMap("files/stat?arg=" + arg + formatStr + "&with-local=" + withLocal);
740
+ }
729
741
public String write(String path, NamedStreamable uploadFile, boolean create, boolean parents) throws IOException {
730
742
String arg = URLEncoder.encode(path, "UTF-8");
731
743
String rpcParams = "files/write?arg=" + arg + "&create=" + create + "&parents=" + parents;
@@ -738,6 +750,19 @@ public String write(String path, NamedStreamable uploadFile, boolean create, boo
738
750
}
739
751
return m.finish();
740
752
}
753
+
754
+ public String write(String path, NamedStreamable uploadFile, WriteFilesArgs args) throws IOException {
755
+ String arg = URLEncoder.encode(path, "UTF-8");
756
+ String rpcParams = "files/write?arg=" + arg + "&" + args.toQueryString();
757
+ URL target = new URL(protocol,host,port,apiVersion + rpcParams);
758
+ Multipart m = new Multipart(target.toString(),"UTF-8");
759
+ if (uploadFile.isDirectory()) {
760
+ throw new IllegalArgumentException("Input must be a file");
761
+ } else {
762
+ m.addFilePart("file", Paths.get(""), uploadFile);
763
+ }
764
+ return m.finish();
765
+ }
741
766
}
742
767
743
768
public class FileStore {
@@ -746,12 +771,12 @@ public Map dups() throws IOException {
746
771
return retrieveMap("filestore/dups");
747
772
}
748
773
749
- public Map ls() throws IOException {
750
- return retrieveMap("filestore/ls" );
774
+ public Map ls(boolean fileOrder ) throws IOException {
775
+ return retrieveMap("filestore/ls?file-order=" + fileOrder );
751
776
}
752
777
753
- public Map verify() throws IOException {
754
- return retrieveMap("filestore/verify" );
778
+ public Map verify(boolean fileOrder ) throws IOException {
779
+ return retrieveMap("filestore/verify?file-order=" + fileOrder );
755
780
}
756
781
}
757
782
@@ -779,6 +804,9 @@ public String reprovide() throws IOException {
779
804
public Map stat() throws IOException {
780
805
return retrieveMap("bitswap/stat");
781
806
}
807
+ public Map stat(boolean verbose, boolean humanReadable) throws IOException {
808
+ return retrieveMap("bitswap/stat?verbose=" + verbose + "&human=" + humanReadable);
809
+ }
782
810
public Map wantlist(Multihash peerId) throws IOException {
783
811
return retrieveMap("bitswap/wantlist?peer=" + peerId);
784
812
}
0 commit comments