UNPKG

@spider-cloud/spider-client

Version:

Isomorphic Javascript SDK for Spider Cloud services

22 lines (21 loc) 665 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createJsonLineProcessor = void 0; const createJsonLineProcessor = (cb) => { let buffer = ""; return (chunk) => { buffer += chunk.toString(); let boundary; while ((boundary = buffer.indexOf("\n")) !== -1) { const line = buffer.slice(0, boundary); buffer = buffer.slice(boundary + 1); if (line.trim()) { try { cb(JSON.parse(line)); } catch (_error) { } } } }; }; exports.createJsonLineProcessor = createJsonLineProcessor;