'use strict'

const UnixFS = require('ipfs-unixfs')
const pull = require('pull-stream')

// Logic to export a single (possibly chunked) unixfs file.
module.exports = (node, name, ds) => {
  const file = UnixFS.unmarshal(node.data)
  let content

  if (node.links.length === 0) {
    content = pull.values([file.data])
  } else {
    content = pull(
      pull.values(node.links),
      pull.map((link) => ds.getStream(link.hash)),
      pull.flatten(),
      pull.map((node) => {
        try {
          const ex = UnixFS.unmarshal(node.data)
          return ex.data
        } catch (err) {
          console.error(node)
          throw new Error('Failed to unmarshal node')
        }
      })
    )
  }

  return pull.values([{
    content: content,
    path: name,
    size: file.fileSize()
  }])
}

@@ -7,16 +7,58 @@
 trict'%0A%0A
+const traverse = require('pull-traverse')%0A
 const Un
@@ -223,16 +223,58 @@
 s) =%3E %7B%0A
+  function getData (node) %7B%0A    try %7B%0A    
   const 
@@ -314,117 +314,165 @@
 )%0A  
-let content%0A%0A  if (node.links.length === 0) %7B%0A    content = pull.values(%5Bfile.data%5D)%0A  %7D else %7B%0A    content =
+    return file.data %7C%7C new Buffer(0)%0A    %7D catch (err) %7B%0A      throw new Error('Failed to unmarshal node')%0A    %7D%0A  %7D%0A%0A  function visitor (node) %7B%0A    return
  pul
@@ -580,216 +580,131 @@
 en()
-,
 %0A    
-  pull.map((node) =%3E %7B%0A        try %7B%0A          const ex = UnixFS.unmarshal(node.data)%0A          return ex.data%0A        %7D catch (err) %7B%0A          console.error(node
+)%0A  %7D%0A%0A  let content = pull(%0A    traverse.depthFirst(node, visitor),%0A    pull.map(getData
 )%0A  
- 
-       throw new Error('Failed to 
+)%0A%0A  const file = UnixFS.
 unma
@@ -712,45 +712,19 @@
 shal
- 
+(
 node
-')%0A        %7D%0A      %7D)%0A    )%0A  %7D%0A
+.data)
 %0A  r

implement recursive file export