This is an automated email from the ASF dual-hosted git repository. glynnbird pushed a commit to branch grb-attachments-are-buffers in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit f8620d73eaac39c9cde9ee6558e6b1bbdadcd866 Author: Glynn Bird <[email protected]> AuthorDate: Fri Aug 21 12:53:35 2026 +0100 always return a Buffer from attachment.get. Fixes issue #373 --- lib/nano.js | 2 +- package-lock.json | 10 +++++----- package.json | 2 +- test/attachment.get.test.js | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/nano.js b/lib/nano.js index d0a3c4b..25c59be 100644 --- a/lib/nano.js +++ b/lib/nano.js @@ -148,7 +148,7 @@ module.exports = exports = function dbScope (cfg) { // when doing head requests, we return the response headers, not the response body if (req.method === 'head') { retval = Object.fromEntries(response.headers) - } else if (contentType && contentType.startsWith('application/json')) { + } else if (contentType && contentType.startsWith('application/json') && !opts.dontParse) { try { retval = await response.json() } catch { diff --git a/package-lock.json b/package-lock.json index 88ed01d..a61fa28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nano", - "version": "11.0.6", + "version": "11.0.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "nano", - "version": "11.0.6", + "version": "11.0.7", "license": "Apache-2.0", "devDependencies": { "@types/node": "^26.1.0", @@ -42,9 +42,9 @@ } }, "node_modules/undici": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-7.28.0.tgz", - "integrity": "sha512-cRZYrTDwWznlnRiPjggAGxZXanty6M8RV1ff8Wm4LWXBp7/IG8v5DnOm74DtUBp9OONpK75YlPnIjQqX0dBDtA==", + "version": "7.29.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.29.0.tgz", + "integrity": "sha512-IDxfleLmmbSskfWSUATiN1nfn2rDuvnMOqb5CWR92iIfojA0Ud+ulOAAEQ57LPr9rWmsreUyf5lwyao+7GNNVw==", "dev": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index f9818f2..2239e29 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "Apache-2.0", "homepage": "http://github.com/apache/couchdb-nano", "repository": "http://github.com/apache/couchdb-nano", - "version": "11.0.6", + "version": "11.0.7", "author": "Apache CouchDB <[email protected]> (http://couchdb.apache.org)", "keywords": [ "couchdb", diff --git a/test/attachment.get.test.js b/test/attachment.get.test.js index fcb70c4..7e10968 100644 --- a/test/attachment.get.test.js +++ b/test/attachment.get.test.js @@ -43,6 +43,21 @@ test('should be able to get an attachment with opts - GET /db/id/attname - db.at mockAgent.assertNoPendingInterceptors() }) +test('should be able to get a JSON attachment as a buffer - GET /db/id/attname - db.attachment.get', async () => { + // mocks + const json = JSON.stringify({ foo: 'bar' }) + mockPool + .intercept({ path: '/db/id/att.json' }) + .reply(200, json, { headers: { 'content-type': 'application/json' } }) + + // test GET /db/id/attname + const db = nano.db.use('db') + const p = await db.attachment.get('id', 'att.json') + assert(Buffer.isBuffer(p), 'JSON attachment should be a buffer') + assert.equal(p.toString(), json) + mockAgent.assertNoPendingInterceptors() +}) + test('should detect missing parameters - db.attachment.get', async () => { const db = nano.db.use('db') await assert.rejects(db.attachment.get(), { message: 'Invalid parameters' })
