From ae312f66d7a6b01a84839353acaf4a407c6bf086 Mon Sep 17 00:00:00 2001
From: "dtube network, vaultec"
 <47548474+dtubenetwork@users.noreply.github.com>
Date: Tue, 11 Jun 2019 22:48:08 -0700
Subject: [PATCH 1/2] Update for latest IPFS, bug fix.

---
 src/index.js | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/src/index.js b/src/index.js
index c3fc872..e833e75 100644
--- a/src/index.js
+++ b/src/index.js
@@ -64,11 +64,11 @@ function getFile(ipfs, rootHash, filename, callback) {
     var hash = null
     var fileSize, fileName
 
-    res.links.forEach(function(link) {
-      if (link.name === filename) {
-        hash = link.cid.toString()
-        fileSize = link.size
-        fileName = link.name
+    res.Links.forEach(function(link) {
+      if (link.Name === filename) {
+        hash = link.Hash.toString()
+        fileSize = link.Tsize
+        fileName = link.Name
         return false
       }
     });
@@ -79,25 +79,16 @@ function getFile(ipfs, rootHash, filename, callback) {
     }
 
     console.log("Requesting '" + rootHash + "/" + filename + "'")
+    
+    const stream = ipfs.cat(hash);
+    stream.then((value) => {
+      console.log("Received data for file '" + rootHash + "/" + fileName + "' size: " + value.length)
+      
+      callback(null, value);
+    }).catch((err) => {
+      callback(err, null);
+    })
 
-    var resBuf = new ArrayBuffer(fileSize)
-    var bufView = new Uint8Array(resBuf)
-    var offs = 0
-
-    const stream = ipfs.catReadableStream(hash)
-    console.log("Received stream for file '" + rootHash + "/" + fileName + "'")
-    stream.on('data', function (chunk) {
-      console.log("Received " + chunk.length + " bytes for file '" +
-        rootHash + "/" + fileName + "'")
-      bufView.set(chunk, offs)
-      offs += chunk.length
-    });
-    stream.on('error', function (err) {
-      callback(err, null)
-    });
-    stream.on('end', function () {
-      callback(null, resBuf)
-    });
   });
 }
 

From 480d4254bff2b6cc1e88ed0410687303d63c294e Mon Sep 17 00:00:00 2001
From: vaultec <47548474+vaultec81@users.noreply.github.com>
Date: Thu, 25 Jul 2019 13:26:24 -0700
Subject: [PATCH 2/2] Update index.js

---
 src/index.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/index.js b/src/index.js
index e833e75..f22fa1f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -66,7 +66,7 @@ function getFile(ipfs, rootHash, filename, callback) {
 
     res.Links.forEach(function(link) {
       if (link.Name === filename) {
-        hash = link.Hash.toString()
+        hash = link.Hash
         fileSize = link.Tsize
         fileName = link.Name
         return false