Skip to content

Commit 0e53b7c

Browse files
committed
object.put with explicit encoding
1 parent a2d0fe7 commit 0e53b7c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/main/java/org/ipfs/api/IPFS.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ public List<MerkleNode> put(List<byte[]> data) throws IOException {
169169
return JSONParser.parseStream(res).stream().map(x -> MerkleNode.fromJSON((Map<String, Object>) x)).collect(Collectors.toList());
170170
}
171171

172+
public List<MerkleNode> put(String encoding, List<byte[]> data) throws IOException {
173+
if (!"json".equals(encoding) && "protobuf".equals(encoding))
174+
throw new IllegalArgumentException("Encoding must be json or protobuf");
175+
Multipart m = new Multipart("http://" + host + ":" + port + version+"object/put?stream-channels=true&encoding="+encoding, "UTF-8");
176+
for (byte[] f : data)
177+
m.addFilePart("file", new NamedStreamable.ByteArrayWrapper(f));
178+
String res = m.finish();
179+
return JSONParser.parseStream(res).stream().map(x -> MerkleNode.fromJSON((Map<String, Object>) x)).collect(Collectors.toList());
180+
}
181+
172182
public MerkleNode get(Multihash hash) throws IOException {
173183
Map json = retrieveMap("object/get?stream-channels=true&arg=" + hash);
174184
json.put("Hash", hash.toBase58());

src/test/java/org/ipfs/api/Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public void objectTest() {
101101
Multihash pointer = Multihash.fromBase58("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB");
102102
MerkleNode object = ipfs.object.get(pointer);
103103
List<MerkleNode> newPointer = ipfs.object.put(Arrays.asList(object.toJSONString().getBytes()));
104+
List<MerkleNode> newPointer2 = ipfs.object.put("json", Arrays.asList(object.toJSONString().getBytes()));
104105
MerkleNode links = ipfs.object.links(pointer);
105106
byte[] data = ipfs.object.data(pointer);
106107
Map stat = ipfs.object.stat(pointer);

0 commit comments

Comments
 (0)