source: node_modules/postgres-bytea/index.js

main
Last change on this file was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 13 days ago

Project Handcraft Marketplace

  • Property mode set to 100644
File size: 863 bytes
Line 
1'use strict'
2
3var bufferFrom = Buffer.from || Buffer
4
5module.exports = function parseBytea (input) {
6 if (/^\\x/.test(input)) {
7 // new 'hex' style response (pg >9.0)
8 return bufferFrom(input.substr(2), 'hex')
9 }
10 var output = ''
11 var i = 0
12 while (i < input.length) {
13 if (input[i] !== '\\') {
14 output += input[i]
15 ++i
16 } else {
17 if (/[0-7]{3}/.test(input.substr(i + 1, 3))) {
18 output += String.fromCharCode(parseInt(input.substr(i + 1, 3), 8))
19 i += 4
20 } else {
21 var backslashes = 1
22 while (i + backslashes < input.length && input[i + backslashes] === '\\') {
23 backslashes++
24 }
25 for (var k = 0; k < Math.floor(backslashes / 2); ++k) {
26 output += '\\'
27 }
28 i += Math.floor(backslashes / 2) * 2
29 }
30 }
31 }
32 return bufferFrom(output, 'binary')
33}
Note: See TracBrowser for help on using the repository browser.