Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Parse and generate RS-delimited JSON sequences according to draft-ietf-json-text-sequence

License

NotificationsYou must be signed in to change notification settings

hildjj/json-text-sequence

Repository files navigation

Parse and generate JSON text sequences as defined inRFC 7464.

JSON text sequences are nice for unambiguous JSON log files. They are resilientto many forms of damage such as truncation, multiple writers incorrectlyconfigured to write to the same file, corrupted JSON, etc. An example sequence:

␞{"d":"2014-09-22T21:58:35.270Z","value":6}␤␞{"d":"2014-09-22T21:59:15.117Z","value":12}␤

Where "␞" is the ASCII "Record Separator" character (U+001E), and "␤" is theASCII "LINE FEED" character (U+000A), otherwise known as "\n".

Installation

npm install json-text-sequence

API

Parsing

To parse the format, pipe an input source into a parser stream:

import{Parser}from'json-text-sequence'importfsfrom'fs'constp=newParser().on('data',obj=>{console.log('JSON:',obj);}).on('truncated',buf=>{console.log('Truncated:',buf);}).on('invalid',buf=>{console.log('Invalid:',buf);}).on('finish',()=>{console.log('DONE');});fs.createReadStream('example.log').pipe(p);

Generation

To generate the format, create a generator, pipe its output somewhereinteresting, then write objects to the generator:

import{Generator}from'json-text-sequence'importfsfrom'fs'constg=newGenerator();g.pipe(fs.createWriteStream('example.log'));g.write({d:newDate(),count:0});

Testscodecov

About

Parse and generate RS-delimited JSON sequences according to draft-ietf-json-text-sequence

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp