
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
socket-sync-buffer
Advanced tools
同步操作socket, 基于 promise, 见例子 examples
网址: https://gitee.com/linuxmail/node-socket-sync-buffer
邮件: eli960@qq.com
基本用法
const socketSyncBuffer = require("socket-sync-buffer").socketSyncBuffer
// host: string, 地址
// port: number, 端口
// ssl?: boolean, 是否开启ssl
// timeout?: number, 读写超时(毫秒)
// rejectUnauthorized?: boolean, 如果证书有问题是否拒绝连接
let socket = new socketSyncBuffer({ host: "127.0.0.1", port: 465, ssl: false, timeout: 0 })
返回值是 boolean 类型, 返回 false 表示连接失败, 返回 true 表示成功
let res = await socket.connect()
返回 null 表示网络失败, 或连接关闭, 否则表示成功, 类型为 Buffer
// 读一行,
let res = await socket.gets()
let res = await socket.readDelimiter("\n")
// 读到指定字符(长度为 1)
// 最多读取 maxSize个字符, maxSize为 0 表示不限制
let res = await socket.readDelimiter(delimiter: string, maxSize: number = 0)
// 读指定长度的数据
let res = await socket.readn(size: number)
// 读数据, 数据长度不定
let res = await socket.read()
返回值是 boolean 类型, 返回 false 表示网络错误,或连接关闭,返回 true 表示成功
// 写 string
let res = await socket.write(str: string)
// 写 Buffer
let res = await socket.writeBuffer(buf: Buffer)
// flush 写缓存
let res = await socket.flush()
返回值是 boolean 类型, 返回 false 表示网络错误,或连接关闭,返回 true 表示成功
let res = await socket.tlsConnect()
返回值是 boolean 类型
// 是否出错, 一般指的是网络错误
let res = socket.isError()
// 是否超时错误
let res = socket.isTimeout()
// 是否连接关闭
let res = socket.isClosed()
有的时候服务会主动返回数据, 用下面这个方法检测
执行一次, 只生效一次, 可读或出错的时候执行 handler,
如果 handler 为 undefined, 则使用上一次的 handler
void setOnExtraDataReadableHandlerOnce(handler: (() => any) | undefined)
FAQs
promise wrap for Net.socket
The npm package socket-sync-buffer receives a total of 2 weekly downloads. As such, socket-sync-buffer popularity was classified as not popular.
We found that socket-sync-buffer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.