BlueGit

timfa posprint

Files

posprint / lib / node / posprint_url.js

posprint_url.js

posprint_url.js 578 B Download Raw
1'use strict';
2
3const zlib = require('zlib');
4
5/**
6 * Build a posprint:// URL from a .pos document (object or JSON string).
7 *
8 * Encoding: UTF-8 JSON → raw deflate → base64url (no padding).
9 *
10 * @param {object|string} pos
11 * @returns {string}
12 */
13function posprintUrl(pos) {
14 const json = typeof pos === 'string' ? pos : JSON.stringify(pos);
15 const compressed = zlib.deflateRawSync(Buffer.from(json, 'utf8'), { level: 9 });
16 const b64 = compressed.toString('base64url');
17 return `posprint://print?v=1&d=${b64}`;
18}
19
20module.exports = { posprintUrl };