Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
StorageBase
✓ const StorageBase = require('ghost-storage-base');
✗ import StorageBase from 'ghost-storage-base';
Package is CommonJS-only; no ES module support. Using ES import syntax will fail with a SyntaxError.
StorageBase
✓ const { StorageBase } = require('ghost-storage-base');
✗ const StorageBase = require('ghost-storage-base').default;
Export is a single constructor, not a default export. Using .default results in undefined.
StorageBase.prototype.save
✓ class MyAdapter extends StorageBase { save(file) { ... } }
✗ const adapter = new StorageBase(); adapter.save = ...;
You must extend the class and implement the abstract methods; do not instantiate StorageBase directly as it throws errors.
Shows how to extend StorageBase with a simple filesystem adapter implementing all required methods.
const StorageBase = require('ghost-storage-base');
const path = require('path');
const fs = require('fs').promises;
class MyAdapter extends StorageBase {
async save(file) {
const targetPath = path.join('/tmp/uploads', file.name);
await fs.writeFile(targetPath, file.buffer);
return targetPath;
}
async exists(fileName, targetDir) {
const filePath = path.join(targetDir || '/tmp/uploads', fileName);
try {
await fs.access(filePath);
return true;
} catch (err) {
return false;
}
}
serve() {
return (req, res, next) => {
res.sendFile(path.join('/tmp/uploads', req.path));
};
}
async delete(fileName, targetDir) {
const filePath = path.join(targetDir || '/tmp/uploads', fileName);
await fs.unlink(filePath);
}
async read(options) {
const filePath = options.path;
return fs.readFile(filePath);
}
async readBytes(options) {
const { path: filePath, start, end } = options;
const fd = await fs.open(filePath, 'r');
const buffer = Buffer.alloc(end - start + 1);
await fd.read(buffer, 0, buffer.length, start);
await fd.close();
return buffer;
}
}
module.exports = MyAdapter;
Errors
Common errors & fixes
TypeError: StorageBase is not a constructor
Using ES import syntax or incorrect require path.
fixUse `const StorageBase = require('ghost-storage-base');` (CommonJS). Error: The 'save' method must be overridden by subclasses of StorageBase
Attempting to instantiate StorageBase directly without extending it.
fixCreate a subclass and implement all abstract methods (save, exists, serve, delete, read, readBytes).
TypeError: adapter.serve is not a function
Missing implementation of serve() in the custom adapter.
fixImplement serve() method that returns a middleware function.
Audit
Dependencies
ghost-ignitionrequiredProvides logging and error handling utilities used by the base class
bluebirdrequiredPromise library for asynchronous operations (legacy dependency)