# safe-buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][npm-url]
#### Safer Node.js Buffer API
**Use the new Node.js v6 Buffer APIs (`Buffer.from`, `Buffer.alloc`,
`Buffer.allocUnsafe`, `Buffer.allocUnsafeSlow`) in Node.js v0.10, v0.12, v4.x, and v5.x.**
**Uses the built-in implementations when available.**
[travis-image]: https://img.shields.io/travis/feross/safe-buffer.svg
[travis-url]: https://travis-ci.org/feross/safe-buffer
[npm-image]: https://img.shields.io/npm/v/safe-buffer.svg
[npm-url]: https://npmjs.org/package/safe-buffer
[downloads-image]: https://img.shields.io/npm/dm/safe-buffer.svg
## install
```
npm install safe-buffer
```
## usage
The goal of this package is to provide a safe replacement for the node.js `Buffer`.
It's a drop-in replacement for `Buffer`. You can use it by adding one `require` line to
the top of your node.js modules:
```js
var Buffer = require('safe-buffer').Buffer
// Existing buffer code will continue to work without issues:
new Buffer('hey', 'utf8')
new Buffer([1, 2, 3], 'utf8')
new Buffer(obj)
new Buffer(16) // create an uninitialized buffer (potentially unsafe)
// But you can use these new explicit APIs to make clear what you want:
Buffer.from('hey', 'utf8') // convert from many types to a Buffer
Buffer.alloc(16) // create a zero-filled buffer (safe)
Buffer.allocUnsafe(16) // create an uninitialized buffer (potentially unsafe)
```
## api
### Class Method: Buffer.from(array)
<!-- YAML
added: v3.0.0
-->
* `array` {Array}
Allocates a new `Buffer` using an `array` of octets.
```js
const buf = Buffer.from([0x62,0x75,0x66,0x66,0x65,0x72]);
// creates a new Buffer containing ASCII bytes
// ['b','u','f','f','e','r']
```
A `TypeError` will be thrown if `array` is not an `Array`.
### Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
<!-- YAML
added: v5.10.0
-->
* `arrayBuffer` {ArrayBuffer} The `.buffer` property of a `TypedArray` or
a `new ArrayBuffer()`
* `byteOffset` {Number} Default: `0`
* `length` {Number} Default: `arrayBuffer.length - byteOffset`
When passed a reference to the `.buffer` property of a `TypedArray` instance,
the newly created `Buffer` will share the same allocated memory as the
TypedArray.
```js
const arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;
const buf = Buffer.from(arr.buffer); // shares the memory with arr;
console.log(buf);
// Prints: <Buffer 88 13 a0 0f>
// changing the TypedArray changes the Buffer also
arr[1] = 6000;
console.log(buf);
// Prints: <Buffer 88 13 70 17>
```
The optional `byteOffset` and `length` arguments specify a memory range within
the `arrayBuffer` that will be shared by the `Buffer`.
```js
const ab = new ArrayBuffer(10);
const buf = Buffer.from(ab, 0, 2);
console.log(buf.length);
// Prints: 2
```
A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer`.
### Class Method: Buffer.from(buffer)
<!-- YAML
added: v3.0.0
-->
* `buffer` {Buffer}
Copies the passed `buffer` data onto a new `Buffer` instance.
```js
const buf1 = Buffer.from('buffer');
const buf2 = Buffer.from(buf1);
buf1[0] = 0x61;
console.log(buf1.toString());
// 'auffer'
console.log(buf2.toString());
// 'buffer' (copy is not changed)
```
A `TypeError` will be thrown if `buffer` is not a `Buffer`.
### Class Method: Buffer.from(str[, encoding])
<!-- YAML
added: v5.10.0
-->
* `str` {String} String to encode.
* `encoding` {String} Encoding to use, Default: `'utf8'`
Creates a new `Buffer` containing the given JavaScript string `str`. If
provided, the `encoding` parameter identifies the character encoding.
If not provided, `encoding` defaults to `'utf8'`.
```js
const buf1 = Buffer.from('this is a tést');
console.log(buf1.toString());
// prints: this is a tést
console.log(buf1.toString('ascii'));
// prints: this is a tC)st
const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');
console.log(buf2.toString());
// prints: this is a tést
```
A `TypeError` will be thrown if `str` is not a string.
### Class Method: Buffer.alloc(size[, fill[, encoding]])
<!-- YAML
added: v5.10.0
-->
* `size` {Number}
* `fill` {Value} Default: `undefined`
* `encoding` {String} Default: `utf8`
Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the
`Buffer` will be *zero-filled*.
```js
const buf = Buffer.alloc(5);
console.log(buf);
// <Buffer 00 00 00 00 00>
```
The `size` must be less than or equal to the value of
`require('buffer').kMaxLength` (on 64-bit architectures, `kMaxLength` is
`(2^31)-1`). Otherwise, a [`RangeError`][] is thrown. A zero-length Buffer will
be created if a `size` less than or equal to 0 is specified.
If `fill` is specified, the allocated `Buffer` will be initialized by calling
`buf.fill(fill)`. See [`buf.fill()`][] for more information.
```js
const buf = Buffer.alloc(5, 'a');
console.log(buf);
// <Buffer 61 61 61 61 61>
```
If both `fill` and `encoding` are specified, the allocated `Buffer` will be
initialized by calling `buf.fill(fill, encoding)`. For example:
```js
const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
console.log(buf);
// <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
```
Calling `Buffer.alloc(size)` can be significantly slower than the alternative
`Buffer.allocUnsafe(size)` but ensures that the newly created `Buffer` instance
contents will *never contain sensitive data*.
A `TypeError` will be thrown if `size` is not a number.
### Class Method: Buffer.allocUnsafe(size)
<!-- YAML
added: v5.10.0
-->
* `size` {Number}
Allocates a new *non-zero-filled* `Buffer` of `size` bytes. The `size` must
be less than or equal to the value of `require('buffer').kMaxLength` (on 64-bit
architectures, `kMaxLength` is `(2^31)-1`). Otherwise, a [`RangeError`][] is
thrown. A zero-length Buffer will be created if a `size` less than or equal to
0 is specified.
The underlying memory for `Buffer` instances created in this way is *not
initialized*. The contents of the newly created `Buffer` are unknown and
*may contain sensitive data*. Use [`buf.fill(0)`][] to initialize such
`Buffer` instances to zeroes.
```js
const buf = Buffer.allocUnsafe(5);
console.log(buf);
// <Buffer 78 e0 82 02 01>
// (octets will be different, every time)
buf.fill(0);
console.log(buf);
// <Buffer 00 00 00 00 00>
```
A `TypeError` will be thrown if `size` is not a number.
Note that the `Buffer` module pre-allocates an internal `Buffer` instance of
size `Buffer.poolSize` that is used as a pool for the fast allocation of new
`Buffer` instances created using `Buffer.allocUnsafe(size)` (and the deprecated
`new Buffer(size)` constructor) only when `size` is less than or equal to
`Buffer.poolSize >> 1` (floor of `Buffer.poolSize` divided by two). The default
value of `Buffer.poolSize` is `8192` but can be modified.
Use of this pre-allocated internal memory pool is a key difference between
calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
Specifically, `Buffer.alloc(size, fill)` will *never* use the internal Buffer
pool, while `Buffer.allocUnsafe(size).fill(fill)` *will* use the internal
Buffer pool if `size` is less than or equal to half `Buffer.poolSize`. The
difference is subtle but can be important when an application requires the
additional performance that `Buffer.allocUnsafe(size)` provides.
### Class Method: Buffer.allocUnsafeSlow(size)
<!-- YAML
added: v5.10.0
-->
* `size` {Number}
Allocates a new *non-zero-filled* and non-pooled `Buffer` of `size` bytes. The
`size` must be less than or equal to the value of
`require('buffer').kMaxLength` (on 64-bit architectures, `kMaxLength` is
`(2^31)-1`). Otherwise, a [`RangeError`][] is thrown. A zero-length Buffer will
be created if a `size` less than or equal to 0 is specified.
The underlying memory for `Buffer` instances created in this way is *not
initialized*. The contents of the newly created `Buffer` are unknown and
*may contain sensitive data*. Use [`buf.fill(0)
没有合适的资源?快使用搜索试试~ 我知道了~
一个棋类游戏实现了中国象棋游戏_JavaScript_代码_下载
共989个文件
meta:485个
png:214个
mp3:106个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 3 下载量 60 浏览量
2022-06-24
15:48:41
上传
评论 1
收藏 12.31MB ZIP 举报
温馨提示
一个棋类游戏实现了中国象棋游戏--红石。它的客户端是cocos creator写的,服务器是node.js写的,服务端是一个非常简单的服务器。使用MySQL存储信息。 文件组成 客户端:客户端,使用 Cocos Creator 打开智能 sever:服务器端。使用node.js编写,是一个学习的服务器,只是做一个简单的极简制作,翻译使用。 client_console:客户端测试程序,可以模拟登陆,进房间。 服务器服务器配置 用的是mysql,所以得先在mysql中运行一个名为hongshi的数据库,然后导入hongshi.sql。 然后npm安装一下需要的包,主要是ws,express,不然你运行node server.js提示缺什么就npm install什么。 我没有写配置文件,你有一点时间查看配置文件,然后直接npm install就可以了。 node server.js运行服务器程序。 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
一个棋类游戏实现了中国象棋游戏_JavaScript_代码_下载 (989个子文件)
create_room_button.anim 2KB
button_start.anim 2KB
weishang_res.pvr.ccz 34KB
WeiShang2.csb 5KB
WeiShang1.csb 5KB
Game.fire 968KB
Hall.fire 113KB
Login.fire 18KB
font_discount.fnt 2KB
price_number.fnt 2KB
gold_num.fnt 1KB
fnt_score_num_1.fnt 1KB
fnt_score_num_2.fnt 1KB
fnt_score_num_0.fnt 1KB
font_zuanshi.fnt 1KB
num_clock.fnt 1KB
.gitignore 2KB
.gitignore 15B
login_bg.jpg 189KB
socket.io.js 180KB
gameManager.js 36KB
Game.js 32KB
WebSocket.js 20KB
pokerPutHelper.js 20KB
pokerPutHelper.js 19KB
Receiver.js 13KB
GameMusicPlayer.js 11KB
PerMessageDeflate.js 10KB
SDKManager.js 10KB
Sender.js 10KB
WebSocketServer.js 9KB
Player.js 9KB
OtherPlayer.js 7KB
uicreator.js 5KB
RecordMainPanel.js 5KB
CreateRoomPanel.js 4KB
EventTarget.js 4KB
ResultPanel.js 4KB
nativeLoader.js 4KB
Login.js 3KB
FinalResultPanel.js 3KB
index.js 3KB
Hall.js 3KB
InviteCodePanel.js 3KB
test.js 3KB
EnterRoomPanel.js 3KB
netEngine.js 3KB
ResultItem.js 2KB
FinalResultItem.js 2KB
netEngine.js 2KB
SharePanel.js 2KB
StarClickPanel.js 2KB
paynotice.js 2KB
paynotice_demo.js 2KB
server.js 2KB
OfflinePanel.js 2KB
RecordDetailPanel.js 2KB
audioPlayer.js 2KB
CardStorePlace.js 2KB
dbManager.js 2KB
BufferUtil.js 2KB
AgentPanel.js 2KB
Extensions.js 2KB
quitGameRequestPanel.js 2KB
SettingItem.js 1KB
index.js 1KB
AnimInAndOut.js 1KB
login_demo.js 1KB
login.js 1KB
UserInfoPanel.js 1KB
ChatPanel.js 1KB
starBlinkAndMove.js 1KB
RecordMainItem.js 1KB
BroadcastPanel.js 1KB
BroadcastItem.js 1KB
ConvenientTalkItem.js 987B
FaceShakeItem.js 987B
RecordDataItem.js 980B
ShopPanel.js 979B
assist.js 958B
ScreenShoter.js 953B
ToolStorePlace.js 949B
SettingPanel.js 886B
broadcast.js 816B
AnimMoveInAndOut.js 809B
WaitingLayout.js 808B
NodeSwitcher.js 787B
ErrorCodes.js 783B
picDownloader.js 780B
getPlayerInfo.js 722B
ChatWordItem.js 687B
ScreenMessage.js 683B
register.js 660B
blink.js 649B
login.js 649B
createNewRoom.js 619B
ShopSelectedItem.js 617B
FlagRotate.js 607B
AdwordsPageViewRoller.js 530B
getRecord.js 480B
共 989 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
- weixin_524496172024-05-01感谢大佬分享的资源给了我灵感,果断支持!感谢分享~
- 柒沐木2024-04-06资源很实用,内容详细,值得借鉴的内容很多,感谢分享。
- 766289362023-04-26资源内容详尽,对我有使用价值,谢谢资源主的分享。
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功