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

@bytedo/buffer

v1.0.1

Published

Buffer浏览器版本,提供常用的API封装

Downloads

1

Readme

Buffer

浏览器版的 Buffer 对象模拟, 提供近似 Node.js 的 BUffer 对象的 API。

@bytedo/buffer

文档

以下方法的 encoding, 如无特殊说明, 均只支持utf8(默认),base64, hex, binary4 种。

静态方法

Buffer.from(data, offsetOrEncoding, end)

Node.js版基本一致, 支持从数组/字符串等值中创建 Buffer 对象。

Buffer.alloc(len, str, encoding)

Node.js版基本一致, 创建指定字节长度的 Buffer, 同时填充内容。

Buffer.concat(list, totalLength)

Node.js版基本一致, 合并多个 Buffer 对象, 可指定总字节长度。

Buffer.isBuffer(target)

Node.js版基本一致, 判断指定值是否为 Buffer 对象。

Buffer.compare(buf1, buf2)

Node.js版基本一致, 比较 2 个 Buffer 对象, 通常用于排序中, 返回-1/0/1

Buffer.byteLength(data, encoding)

Node.js版基本一致, 返回给定内容的字节长度, 内容可以是任意类型。

实例方法

.toString(encoding, start, end)

Node.js版基本一致, 将Buffer对象转为字符串。 其中encoding支持utf8(默认),base64, hex, binary4 种。

.fill(val, start, end, encoding)

Node.js版基本一致, 向 Buffer 对象中填充内容, 可填充到指定位置。

.copy(target, targetStart, sourceStart, sourceEnd)

向目标对象中复制当前对象, 注意, 该方法改变的不是自身, 是传入的对象, 这个行为与Node.js版一致。

.write(val, offset, len, encoding)

Node.js版基本一致, 指定位置写入数据, 可以是任意类型。

.compare(buf)

与静态方法的功能一样, 只是这里比较的对象是自身, 返回-1/0/1

.equals(buf)

Node.js版基本一致, 判断与给定的对象是否一致, 返回true/false

.includes(data, offset, encoding)

Node.js版基本一致, 判断给定内容是否包含在内, 可从指定位置开始判断, 返回true/false

其他操作

Buffer 对象, 可以直接用于创建文件对象, 如下

let file = new File([Buffer.from('这是一段文本')], 'demo.txt', {
  type: 'text/plain'
})

console.log(file)

但是由于浏览器端暂不支持非异步的方法将Blob/File对象转成ArrayBuffer, 所以暂时不支持从Blob/File中创建Buffer对象.