@@ -2,6 +2,7 @@ const Archiver = require('hypercore-archiver')
22const mkdirp = require ( 'mkdirp' )
33const encoding = require ( 'dat-encoding' )
44const hyperdrive = require ( 'hyperdrive' )
5+ const pages = require ( 'random-access-page-files' )
56const Swarm = require ( 'discovery-swarm' )
67const swarmDefaults = require ( 'datland-swarm-defaults' )
78const hyperhttp = require ( 'hyperdrive-http' )
@@ -12,7 +13,7 @@ module.exports = Dats
1213function Dats ( dir ) {
1314 if ( ! ( this instanceof Dats ) ) return new Dats ( dir )
1415 mkdirp . sync ( dir )
15- this . archiver = Archiver ( { dir : dir , sparse : true } )
16+ this . archiver = Archiver ( { dir : dir , sparse : true , storage : pages } )
1617 this . swarm = createSwarm ( this . archiver )
1718 this . drive = hyperdrive ( this . archiver . db )
1819 this . archives = { }
@@ -24,13 +25,15 @@ Dats.prototype.get = function (key, cb) {
2425 key = encoding . toStr ( key )
2526 var buf = encoding . toBuf ( key )
2627 if ( self . archives [ key ] ) return cb ( null , self . archives [ key ] )
27- self . archiver . add ( buf , { content : false } , function ( err ) {
28+ self . archiver . add ( buf , { content : true } , function ( err ) {
2829 if ( err ) return cb ( err )
2930 self . archiver . get ( buf , function ( err , metadata , content ) {
3031 if ( err ) return cb ( err )
31- var archive = self . drive . createArchive ( buf , { metadata : metadata , content : content } )
32- self . archives [ key ] = archive
33- return cb ( null , archive )
32+ if ( content ) {
33+ var archive = self . drive . createArchive ( buf , { metadata : metadata , content : content } )
34+ self . archives [ key ] = archive
35+ return cb ( null , archive )
36+ }
3437 } )
3538 } )
3639}
0 commit comments