Registry / storage / ghost-storage-base

ghost-storage-base

JSON →
library1.1.2jsnpmunverified

Base storage adapter class for Ghost content management system. Version 1.1.2 provides the abstract base for building custom storage backends (filesystem, S3, Google Cloud, etc.). Low release cadence as the API is stable. Differentiates by enforcing Ghost's storage contract: requires implementing `save`, `exists`, `serve`, `delete`, `read`, and `readBytes` methods. Primarily used internally by Ghost but published for custom adapter developers.

npm install ghost-storage-base
INSTALL
IMPORT
SIG · GHOST-STORAGE-BASE
G
ghost-storage-base
storagejavascriptv1.1.2
harness data pending
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;
Debug
Known issues
breakingVersion 1.0.0 changed the `save` method signature: now receives a file object instead of separate parameters.
fix
Update custom adapters to accept single file object with `name`, `buffer`, etc.
affects: >=1.0.0
deprecatedThe package uses `ghost-ignition` which is deprecated in favor of `@tryghost/logging`.
fix
Replace `ghost-ignition` imports with `@tryghost/logging` and update error handling accordingly.
affects: >=0.1.0
gotchaThe `serve` method must return a middleware function (req, res, next) - not a static file path.
fix
Ensure `serve()` returns a function that handles the HTTP response, not just a string.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: StorageBase is not a constructor
Using ES import syntax or incorrect require path.
fix
Use `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.
fix
Create 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.
fix
Implement serve() method that returns a middleware function.
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies
ghost-ignitionrequiredProvides logging and error handling utilities used by the base class
bluebirdrequiredPromise library for asynchronous operations (legacy dependency)
Agent activity
13 hits · last 30 days
node
12
Amazon
1
Resources
ghost-storage-base — npm install ghost-storage-base · libregistry