@@ -30,6 +30,7 @@ public enum PinType {all, direct, indirect, recursive}
3030 private final int readTimeoutMillis ;
3131 public final Key key = new Key ();
3232 public final Log log = new Log ();
33+ public final MultibaseAPI multibase = new MultibaseAPI ();
3334 public final Pin pin = new Pin ();
3435 public final Repo repo = new Repo ();
3536 public final IPFSObject object = new IPFSObject ();
@@ -262,6 +263,55 @@ public Map ls() throws IOException {
262263 return retrieveMap ("log/ls" );
263264 }
264265 }
266+ public class MultibaseAPI {
267+ public String decode (NamedStreamable encoded_file ) {
268+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + version +
269+ "multibase/decode" , "UTF-8" );
270+ try {
271+ if (encoded_file .isDirectory ()) {
272+ throw new IllegalArgumentException ("encoded_file must be a file" );
273+ } else {
274+ m .addFilePart ("file" , Paths .get ("" ), encoded_file );
275+ return m .finish ();
276+ }
277+ } catch (IOException e ) {
278+ throw new RuntimeException (e .getMessage (), e );
279+ }
280+ }
281+ public String encode (Optional <String > encoding , NamedStreamable file ) {
282+ String b = encoding .map (f -> "?b=" + f ).orElse ("?b=base64url" );
283+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + version +
284+ "multibase/encode" + b , "UTF-8" );
285+ try {
286+ if (file .isDirectory ()) {
287+ throw new IllegalArgumentException ("Input must be a file" );
288+ } else {
289+ m .addFilePart ("file" , Paths .get ("" ), file );
290+ return m .finish ();
291+ }
292+ } catch (IOException e ) {
293+ throw new RuntimeException (e .getMessage (), e );
294+ }
295+ }
296+ public List <Map > list (boolean prefix , boolean numeric ) throws IOException {
297+ return (List )retrieveAndParse ("multibase/list?prefix=" + prefix + "&numeric=" + numeric );
298+ }
299+ public String transcode (Optional <String > encoding , NamedStreamable file ) {
300+ String b = encoding .map (f -> "?b=" + f ).orElse ("?b=base64url" );
301+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + version +
302+ "multibase/transcode" + b , "UTF-8" );
303+ try {
304+ if (file .isDirectory ()) {
305+ throw new IllegalArgumentException ("Input must be a file" );
306+ } else {
307+ m .addFilePart ("file" , Paths .get ("" ), file );
308+ return m .finish ();
309+ }
310+ } catch (IOException e ) {
311+ throw new RuntimeException (e .getMessage (), e );
312+ }
313+ }
314+ }
265315
266316 /* 'ipfs repo' is a plumbing command used to manipulate the repo.
267317 */
0 commit comments