Skip to content

Commit

Permalink
feat(util): Add method to write DDO to cache folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Prash74 committed Dec 6, 2019
1 parent a83820f commit 1c76717
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { createIdentityKeyPath } = require('./key-path')
const { dirname, resolve } = require('path')
const { dirname, resolve, join } = require('path')
const isBuffer = require('is-buffer')
const mkdirp = require('mkdirp')
const debug = require('debug')('ara:identity:util')
const pify = require('pify')
const dns = require('ara-identity-dns')
const fs = require('fs')
const os = require('os')
/* eslint-disable no-await-in-loop */

/**
Expand Down Expand Up @@ -104,9 +106,21 @@ async function resolveDNS(uri) {
return null
}

async function writeCache(identifier, buffer) {
try {
const cachePath = join(os.tmpdir(), 'aid', identifier, 'ddo.json')
await pify(mkdirp)(dirname(cachePath))
await pify(fs.writeFile)(cachePath, buffer)
} catch (err) {
debug(err)
}
return true
}

module.exports = {
ethHexToBuffer,
writeIdentity,
writeCache,
resolveDNS,
toBuffer,
toHex,
Expand Down

0 comments on commit 1c76717

Please sign in to comment.