# safe-buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
[travis-image]: https://img.shields.io/travis/feross/safe-buffer/master.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
[downloads-url]: https://npmjs.org/package/safe-buffer
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com
#### Safer Node.js Buffer API
**Use the new Node.js Buffer APIs (`Buffer.from`, `Buffer.alloc`,
`Buffer.allocUnsafe`, `Buffer.allocUnsafeSlow`) in all versions of Node.js.**
**Uses the built-in implementation when available.**
## 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` l
22级软件技术03班.zip
需积分: 0 136 浏览量
更新于2024-01-20
收藏 3.24MB ZIP 举报
【标题与描述解析】
标题"22级软件技术03班.zip"暗示这可能是一个教育相关的文件包,其中包含了22级(可能是2022级,指的是2022年入学的学生)软件技术专业03班级的学习资料、作业、项目或者课程大纲等。由于描述与标题相同,没有提供额外的信息,我们可以推测这个压缩包是为了教学或学习目的而创建的,可能包含了一系列的文档、代码、课件或其他与软件技术相关的资源。
【知识领域】
1. **软件技术**:这是一个宽泛的领域,涵盖了编程语言、软件开发方法、数据结构、算法、操作系统、计算机网络、数据库管理等多个子领域。22级学生可能正在学习基础的编程概念,如C++、Java或Python,并逐步接触更高级的主题,如面向对象编程、软件工程、前端和后端开发等。
2. **编程语言**:作为软件技术的一部分,学生可能会接触到各种编程语言,如C、C++、Java、Python、JavaScript等。每种语言都有其特定的应用场景和语法特性,学习过程中会涉及到变量、控制结构、函数、类等基本概念。
3. **软件工程**:这部分内容可能包括需求分析、设计、编码、测试和维护等软件开发的整个生命周期。学生们可能在学习如何编写规范的代码、创建项目文档、使用版本控制系统(如Git)以及合作开发技巧。
4. **数据结构与算法**:这是软件开发中的核心部分,涵盖了数组、链表、栈、队列、树、图等数据结构,以及排序、搜索等算法。理解并能有效运用这些数据结构和算法是解决复杂问题的基础。
5. **数据库管理**:SQL语言的学习是必不可少的,学生可能会接触到关系型数据库的基本操作,如创建表、查询数据、事务处理等,也可能涉及NoSQL数据库的概念。
6. **操作系统**:理解操作系统的工作原理,包括进程、线程、内存管理、文件系统等,对于软件开发人员来说至关重要。
7. **计算机网络**:学习网络协议(如TCP/IP)、网络架构、网络安全、客户端-服务器模型等,有助于理解如何构建分布式系统。
8. **项目实战**:学生可能会参与实际的软件开发项目,通过实践来巩固理论知识,提升编程技能。
9. **软件设计与架构**:设计模式、软件架构风格(如MVC、微服务架构等)的学习,能够帮助学生理解如何构建可扩展、可维护的系统。
10. **前端与后端开发**:前端可能涵盖HTML、CSS、JavaScript等,用于构建用户界面;后端可能涉及到服务器端编程,如Node.js、Django、Spring Boot等框架的使用。
【文件名称列表】
由于只有一个名为"22级软件技术03班"的文件,我们无法确定具体的内容。通常,这样的文件可能是一个目录文件或者包含课程介绍、课件、习题解答、源代码等各类资料的集合。每个子文件可能分别对应一个课程主题,例如“第一周-编程基础.pdf”、“第二周-数据结构.pptx”等。
总结,这个压缩包可能是为了支持22级软件技术03班学生的课程学习而准备的,涵盖了广泛的知识点,从基础编程到高级软件开发技术。学生可以通过解压并探索文件内容来深入了解和掌握软件技术领域的各种概念和技能。
2401_82740410
- 粉丝: 0
- 资源: 1
最新资源
- 15-面试题库(14个维度选拔考查).doc
- 28-绝对必备:HR经理面试提问大全(100问).doc
- 25-100个最权威的招聘面试题及回答解析.doc
- 27-HR经理常用的21个经典面试问题.doc
- 21-HR经理面试问题样例大全(30余种能力考查).doc
- 23-《职业测评--职场成功测评之完整题库》附答案.doc
- 26-200个名企的面试题详解(微软+谷歌+联合利华).doc
- 22-101个面试难题及结构化面试题库(附点评).doc
- 31-世界五百强面试题目及应答评点(全套50题).doc
- 30-面试通用题库以及压力测试.doc
- 29-面试通关秘笈:面试过程中常见的刁钻问题汇总.docx
- 32-招聘专员必备《HR结构化面试题库大全及解析》.doc
- python条件语句和高级应用
- 金属拉链穿头机(sw10可编辑+工程图)全套技术资料100%好用.zip
- 家具设备1出2三角木头机(sw18可逼哪家+工程图+BOM)全套技术资料100%好用.zip
- 1-销售面试题.xls