UNPKG

853 BJavaScriptView Raw
1'use strict';
2var StorageDriver = require('../lib/StorageDriver')
3
4//the actual storage handle
5var store = {}
6
7var driver = StorageDriver.create('memory')
8
9
10/**
11 * Save
12 * @param {string} handle
13 * @param {object} data
14 * @param {function} next
15 */
16driver.prototype.save = function(handle,data,next){
17 store[handle] = data
18 next()
19}
20
21
22/**
23 * Restore
24 * @param {string} handle
25 * @param {function} next
26 */
27driver.prototype.restore = function(handle,next){
28 if('object' === typeof store[handle]){
29 next(null,store[handle])
30 } else {
31 next('restoration of handle (' + handle + ') failed, handle doesnt exist')
32 }
33}
34
35
36/**
37 * Flush
38 * @param {string} handle
39 * @param {function} next
40 */
41driver.prototype.flush = function(handle,next){
42 delete store[handle]
43 next()
44}
45
46
47/**
48 * Export driver
49 * @type {StorageDriver}
50 */
51module.exports = driver