nv-buf-utf8-boundary
1.0.1 • Public • Published
- check incomplete utf8 1b 2b 3b 4b in a buffer-tail
- npm install nv-buf-utf8-boundary
const { check} = require("nv-buf-utf8-boundary");
> Buffer.from(String.fromCodePoint(65536))
<Buffer f0 90 80 80>
> buf = Buffer.from(String.fromCodePoint(65536))
<Buffer f0 90 80 80>
>
> x.check(buf)
[ 4, [] ]
> buf[3]=buf[2]
128
> buf[2]=buf[1]
144
> buf[1]=buf[0]
240
> buf[0]=97
97
> buf
<Buffer 61 f0 90 80>
> x.check(buf)
[ 1, [ 240, 144, 128 ] ]
>
> buf[3]=buf[2]
144
> buf[2]=buf[1]
240
> buf[1]=buf[0]
97
> buf[0]=98
98
> x.check(buf)
[ 2, [ 240, 144 ] ]
>
> buf
<Buffer 62 61 f0 90>
> buf[3]=buf[2]
240
> buf[2]=buf[1]
97
> buf[1]=buf[0]
98
> buf[0]=99
99
> x.check(buf)
[ 3, [ 240 ] ]
> buf
<Buffer 63 62 61 f0>
>
buf[0] = 96
> x.check(buf)
[ 4, [] ]
>
Package Sidebar
Install
npm i nv-buf-utf8-boundary
Weekly Downloads