rfsmix.js 540 B

1234567891011121314151617181920212223
  1. module.exports = function(opt, store){
  2. var rfs = require('./rfs')(opt);
  3. var p = store.put;
  4. var g = store.get;
  5. store.put = function(file, data, cb){
  6. var a, b, c = function(err, ok){
  7. if(b){ return cb(err || b) }
  8. if(a){ return cb(err, ok) }
  9. a = true;
  10. b = err;
  11. }
  12. p(file, data, c); // parallel
  13. rfs.put(file, data, c); // parallel
  14. }
  15. store.get = function(file, cb){
  16. rfs.get(file, function(err, data){
  17. //console.log("rfs3 hijacked", file);
  18. if(data){ return cb(err, data) }
  19. g(file, cb);
  20. });
  21. }
  22. return store;
  23. }