npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oput

v1.2.2

Published

0 put do

Downloads

11

Readme

0 put do 零存整取库

codecov

该库旨在解决js需要缓存内存块来解决接收不定长度的数据,取出不定长度的数据的问题。例如tcp的粘包问题。

典型需求

接收一个远程请求,不断接收到不定长度的数据,然后根据协议解析到长度字段,然后读取一段长度来解包,此时可能缓存不够,需要等待继续接收数据,如果缓存够了,则读取长度后,需要修改缓存为剩余的数据

用核酸筛查来比喻,陆续有人来排队,需要排满10人为一组进行采样。

安装

$ npm install oput

使用

分成生产端和消费端,生产端负责向OPut中写入数据(TypedArray或者ArrayBuffer)。

import OPut from 'oput'
const oput = new OPut(reader)
oput.write(new Uint32Array([1,2,3]))

可以在pipeTo中使用

import OPut from 'oput'
const oput = new OPut(reader)
readableStream.pipeTo(new WritableStream(oput))

消费端负责从OPut中读取数据。根据实际需要可以选择两种读取模式。

模式一:按字节数读取,返回缓冲中头部N个字节的数据

读取出来的是Uint8Array对象,要及时处理,后续读取出的数据会覆盖前面的数据。

function *reader(){
  let b = yield 5;//读取5个字节
  console.log(b[0])
}

模式二:向生产者提供TypedArray对象,接收数据

可以自行选择是否复用TypedArray对象

function *reader(){
  let b = new Uint8Array(5);
  yield b;//填充到b中
  console.log(b[0])
  b = new Uint32Array(5);
  yield b;//填充到b中,又读取了20个字节
  console.log(b[0])
}

模式三:通过异步read方式读取数据

  const oput = new OPut();
  oput.write(new Uint32Array([1, 2]));
  oput.write(new Uint32Array([1, 2]));
  oput.read(1).then(value=>{
    expect(value[0]).toBe(1)
    return oput.read(4)
  }).then(value=>{
    expect(value[3]).toBe(2)
  })