Registry / storage / pg-large-object

pg-large-object

JSON →
library2.0.0jsnpmunverified

Large object support for PostgreSQL clients using the node-postgres (pg) library, enabling streaming of files/objects up to 4 TiB in size. Version 2.0.0 is current stable. Supports both callback (backwards compatible) and promise (Async suffix) interfaces. Key differentiator: streams data in chunks instead of loading entire column into memory. Requires PostgreSQL 8.4+ (9.3+ for seek/tell/size/truncate). Works with pg or pg-promise.

npm install pg-large-object
INSTALL
IMPORT
SIG · PG-LARGE-OBJECT
P
pg-large-object
storagejavascriptv2.0.0
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.

LargeObjectManager
import { LargeObjectManager } from 'pg-large-object'
const LargeObjectManager = require('pg-large-object')
Named import from ESM (if using bundler/babel). For CommonJS: const { LargeObjectManager } = require('pg-large-object')
LargeObject
import { LargeObject } from 'pg-large-object'
const LargeObject = require('pg-large-object').LargeObject
Named export, not a default export. Both ESM and CJS work with named syntax.
pgPromise
new LargeObjectManager({pgPromise: tx})
new LargeObjectManager({pg: tx})
When using pg-promise, pass the transaction object under 'pgPromise' key, not 'pg'. When using pg, pass the client under 'pg' key.

Demonstrates reading a large object by OID as a stream into a file, using pg-promise and transactions.

const pgp = require('pg-promise')(); const { LargeObjectManager } = require('pg-large-object'); const { createWriteStream } = require('fs'); const db = pgp('postgres://postgres:1234@localhost/postgres'); db.tx(tx => { const man = new LargeObjectManager({ pgPromise: tx }); const oid = 123; return man.openAndReadableStreamAsync(oid, 16384).then(([size, stream]) => { console.log('Streaming large object of size', size); const fileStream = createWriteStream('output.png'); stream.pipe(fileStream); return new Promise((resolve, reject) => { stream.on('end', resolve); stream.on('error', reject); }); }); }).then(() => console.log('Done!')).catch(err => console.error(err));
Debug
Known issues
gotchaMethods seek(), tell(), size(), truncate() require PostgreSQL 9.3+.
fix
Ensure server version >= 9.3 or avoid these methods.
affects: >=0.0.0
gotchaBuffer size should be divisible by 2048 for best performance (matches PostgreSQL LOBLKSIZE).
fix
Use buffer size like 16384, 8192, etc.
affects: >=0.0.0
gotchaMust use a transaction when working with Large Objects; otherwise errors may cause orphaned objects.
fix
Wrap operations in db.tx() or BEGIN/COMMIT.
affects: >=0.0.0
gotchaWhen using pg-promise, pass the transaction object via {pgPromise: tx}, not {pg: tx}.
fix
Use {pgPromise: tx} when using pg-promise, or {pg: client} when using raw pg.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pg-large-object'
Package not installed or not in node_modules.
fix
Run: npm install pg-large-object
TypeError: man.openAndReadableStreamAsync is not a function
Using older version that doesn't have Async methods or incorrect import.
fix
Check that you have version >=2.0.0 (npm view pg-large-object version). Use correct import: const { LargeObjectManager } = require('pg-large-object')
error: relation "pg_largeobject" does not exist
PostgreSQL large object functionality not enabled or permissions issue.
fix
Ensure user has superuser or largeobject privileges. Run as superuser: CREATE EXTENSION IF NOT EXISTS lo;
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
pgrequiredPeer dependency: pg (>=2.7.0) is required; alternatively pg-promise can be used
Agent activity
20 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
pg-large-object — npm install pg-large-object · libregistry