{"_id":"postgres-bytea","_rev":"85506","name":"postgres-bytea","description":"Postgres bytea parser","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"bendrucker","email":"bvdrucker@gmail.com"}],"time":{"modified":"2021-06-03T10:27:43.000Z","created":"2015-06-14T04:44:18.277Z","3.0.0":"2020-06-11T17:25:13.447Z","2.0.0":"2019-04-25T18:09:34.243Z","1.0.0":"2015-06-14T04:44:18.277Z"},"users":{},"author":{"name":"Ben Drucker","email":"bvdrucker@gmail.com","url":"bendrucker.me"},"repository":{"type":"git","url":"git+https://github.com/bendrucker/postgres-bytea.git"},"versions":{"3.0.0":{"name":"postgres-bytea","main":"index.js","version":"3.0.0","description":"Postgres bytea parser","license":"MIT","repository":{"type":"git","url":"git+https://github.com/bendrucker/postgres-bytea.git"},"author":{"name":"Ben Drucker","email":"bvdrucker@gmail.com","url":"bendrucker.me"},"engines":{"node":">= 6"},"scripts":{"test":"standard && tape *.js"},"keywords":["bytea","postgres","binary","parser"],"dependencies":{"obuf":"~1.1.2"},"devDependencies":{"concat-stream":"2.0.0","standard":"^14.0.0","stream-to-promise":"^3.0.0","tape":"^5.0.0","tape-promise":"4.0.0"},"gitHead":"03af680e296ca262c1519ee7a88d4c82eb2ea88f","bugs":{"url":"https://github.com/bendrucker/postgres-bytea/issues"},"homepage":"https://github.com/bendrucker/postgres-bytea#readme","_id":"postgres-bytea@3.0.0","_nodeVersion":"12.16.2","_npmVersion":"6.14.5","dist":{"shasum":"9048dc461ac7ba70a6a42d109221619ecd1cb089","size":3778,"noattachment":false,"key":"/postgres-bytea/-/postgres-bytea-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/postgres-bytea/download/postgres-bytea-3.0.0.tgz"},"maintainers":[{"name":"bendrucker","email":"bvdrucker@gmail.com"}],"_npmUser":{"name":"bendrucker","email":"bvdrucker@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/postgres-bytea_3.0.0_1591896313340_0.7817432110799702"},"_hasShrinkwrap":false,"publish_time":1591896313447,"_cnpm_publish_time":1591896313447},"2.0.0":{"name":"postgres-bytea","main":"index.js","version":"2.0.0","description":"Postgres bytea parser","license":"MIT","repository":{"type":"git","url":"git+https://github.com/bendrucker/postgres-bytea.git"},"author":{"name":"Ben Drucker","email":"bvdrucker@gmail.com","url":"bendrucker.me"},"engines":{"node":">= 6"},"scripts":{"test":"standard && tape test.js"},"keywords":["bytea","postgres","binary","parser"],"dependencies":{},"devDependencies":{"tape":"^4.0.0","standard":"^12.0.1"},"gitHead":"737824ac06318a51a530a7e73cf4fada21ccf9e9","bugs":{"url":"https://github.com/bendrucker/postgres-bytea/issues"},"homepage":"https://github.com/bendrucker/postgres-bytea#readme","_id":"postgres-bytea@2.0.0","_nodeVersion":"10.15.0","_npmVersion":"6.7.0","dist":{"shasum":"97718badcfaadea5f52e9712d1a986c88ddbad2a","size":1745,"noattachment":false,"key":"/postgres-bytea/-/postgres-bytea-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/postgres-bytea/download/postgres-bytea-2.0.0.tgz"},"maintainers":[{"name":"bendrucker","email":"bvdrucker@gmail.com"}],"_npmUser":{"name":"bendrucker","email":"bvdrucker@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/postgres-bytea_2.0.0_1556215774143_0.3380211438492775"},"_hasShrinkwrap":false,"publish_time":1556215774243,"_cnpm_publish_time":1556215774243},"1.0.0":{"name":"postgres-bytea","main":"index.js","version":"1.0.0","description":"Postgres bytea parser","license":"MIT","repository":{"type":"git","url":"git+https://github.com/bendrucker/postgres-bytea.git"},"author":{"name":"Ben Drucker","email":"bvdrucker@gmail.com","url":"bendrucker.me"},"engines":{"node":">=0.10.0"},"scripts":{"test":"standard && tape test.js"},"keywords":["bytea","postgres","binary","parser"],"dependencies":{},"devDependencies":{"tape":"^4.0.0","standard":"^4.0.0"},"files":["index.js","readme.md"],"gitHead":"6a1c2665b40e7a6548d7102a8b0fb4905a1a90b7","bugs":{"url":"https://github.com/bendrucker/postgres-bytea/issues"},"homepage":"https://github.com/bendrucker/postgres-bytea#readme","_id":"postgres-bytea@1.0.0","_shasum":"027b533c0aa890e26d172d47cf9ccecc521acd35","_from":".","_npmVersion":"2.11.0","_nodeVersion":"2.2.1","_npmUser":{"name":"bendrucker","email":"bvdrucker@gmail.com"},"dist":{"shasum":"027b533c0aa890e26d172d47cf9ccecc521acd35","size":1730,"noattachment":false,"key":"/postgres-bytea/-/postgres-bytea-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/postgres-bytea/download/postgres-bytea-1.0.0.tgz"},"maintainers":[{"name":"bendrucker","email":"bvdrucker@gmail.com"}],"directories":{},"publish_time":1434257058277,"_cnpm_publish_time":1434257058277,"_hasShrinkwrap":false}},"readme":"# postgres-bytea [![Build Status](https://travis-ci.org/bendrucker/postgres-bytea.svg?branch=master)](https://travis-ci.org/bendrucker/postgres-bytea) [![Greenkeeper badge](https://badges.greenkeeper.io/bendrucker/postgres-bytea.svg)](https://greenkeeper.io/)\n\n> Decode/encode Postgres bytea strings to Buffers\n\n\n## Install\n\n```sh\nnpm install postgres-bytea\n```\n\n## Usage\n\n### Decoding\n\nTo decode a bytea string into a buffer:\n\n```js\nconst bytea = require('postgres-bytea')\n\n// bytea hex format\nbytea.decode('\\\\x1234') // <Buffer 12 34>\n\n// bytea escape format\nbytea.decode('\\\\000\\\\100\\\\200') // <Buffer 00 40 80>\n```\n\nThe `decode` function supports both the hex format used in Postgres 9+ and the escape format used in Postgres 8 and earlier. It automatically detects the format from the incoming data.\n\nFor backward compatibility, `decode` is also the default export from the package.\n\n### Decoding (Stream)\n\nTo decode a bytea hex stream into binary:\n\n```js\nconst bytea = require('postgres-bytea')\n\nreadable.pipe(new bytea.Decoder())\n```\n\n`Decoder` expects a double-escaped `\\\\x` prefix to allow reading from a `COPY TO` statement.\n\n### Encoding (Stream)\n\n\n```js\nconst bytea = require('postgres-bytea')\n\nreadable.pipe(new bytea.Encoder())\n```\n\n`Encoder` adds a double-escaped `\\\\x` prefix to allow writing to a `COPY FROM` statement.\n\n## API\n\n#### `bytea.decode(input)` -> `buffer`\n\n##### input\n\n*Required*  \nType: `string`\n\nA Postgres bytea binary string.\n\n#### `new bytea.Decoder()` -> `stream.Transform`\n\nCreates a bytea decoder stream that emits buffer chunks.\n\n#### `new bytea.Encoder()` -> `stream.Transform`\n\nCreates a bytea encoder stream that receives buffer chunks and emits them as bytea strings.\n\n## Prefix Escaping\n\n> The “hex” format encodes binary data as 2 hexadecimal digits per byte, most significant nibble first. The entire string is preceded by the sequence \\x (to distinguish it from the escape format). In some contexts, the initial backslash may need to be escaped by doubling it (see Section 4.1.2.1).\n>\n> https://www.postgresql.org/docs/12/datatype-binary.html#id-1.5.7.12.9\n\nA `SELECT` statement returns bytea values using the single-escaped `\\x` prefix. The `COPY TO` and `COPY FROM` commands expect and return bytea values with the double-escaped `\\\\x` prefix. \n\n`bytea.decode` expects the single-escaped prefix. The `Decoder` and `Encoder` streams expect the double-escaped prefix, since they are most useful in `COPY FROM` and `COPY TO` statements.\n\n## License\n\nMIT © [Ben Drucker](http://bendrucker.me)\n","_attachments":{},"homepage":"https://github.com/bendrucker/postgres-bytea#readme","bugs":{"url":"https://github.com/bendrucker/postgres-bytea/issues"},"license":"MIT"}