simple-on-disk-cache
Version:
A simple on-disk cache, supporting local and remote filesystem targets, with time based expiration policies.
22 lines • 1.33 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getObjectAsString = void 0;
const getObject_1 = require("./getObject");
const getObjectAsString = (_a) => __awaiter(void 0, [_a], void 0, function* ({ bucket, key, }) {
const body = yield (0, getObject_1.getObject)({ bucket, key });
const content = body instanceof Buffer ? body.toString() : body; // cast from buffer if needed
if (typeof content !== 'string')
throw new Error('can not get object as json, object is not string');
return content;
});
exports.getObjectAsString = getObjectAsString;
//# sourceMappingURL=getObjectAsString.js.map