Skip to content

Commit 3b36d1f

Browse files
committed
start on streams, add buffer to cheatsheet
1 parent a3888eb commit 3b36d1f

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

buffers-and-streams/buffers.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
layout: default
33
title: Buffers in depth
44
url: buffers
5+
author: john
6+
date: 2019-11-14
57
---
68

79
## Buffers
810

9-
Node's `Buffer` class enables working with binary data in Javascript. A buffer is allows a programme to store data temporarily outside the V8 engine's stack.
11+
Node's `Buffer` class enables working with binary data in Javascript. A buffer allows a programme to store data temporarily outside the V8 engine's stack.
1012

1113
Though not entirely accurate we can think of a buffer as an array of bytes, each byte is represented by a hexadecimal digit.
1214

1315
The Node `Buffer` class is a global class and therefore does not need to be imported into a module.
1416

15-
### A simple example
17+
### Example
1618

1719
```javascript
1820
// create a buffer from a string
@@ -46,6 +48,8 @@ Buffers can also be instantiated by size using `Buffer.alloc()`, `Buffer.allocUn
4648

4749
> _Unsafe_ as the memory containing the buffer is not initialised - i.e. not zeroed-out, so the potential exists for sensitive data to be leaked.
4850
51+
### Example
52+
4953
```
5054
const myBuffer1 = Buffer.from([1, 2, 3]);
5155
console.log(myBuffer1.length);

buffers-and-streams/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
layout: default
33
title: Buffers and Streams
44
url: buffers-and-streams
5+
author: john
6+
date: 2019-11-14
57
---
68

79
The Node Application Developer Certification exam section for Buffers and Streams is worth 11% of the total and is broken into the following sections.

buffers-and-streams/streams.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
layout: default
33
title: Streams in depth
44
url: streams
5+
author: john
6+
date: 2019-11-15
57
---
68

7-
## Streams
9+
## Streams
10+
11+
Node's `stream` module is an API for working with streaming data. Streams enable working with data as it is received rather than waiting for the data to be fully loaded into memory.
12+
13+
An example of streaming data is watching an online video broadcast. As the data is received the video can be displayed.
14+
15+
Streams are instances of [`EventEmitter`](#events).
16+
17+
## Working with streams
18+
19+
To use the `stream` module it must be imported -
20+
21+
`const stream = require('stream');`

cheatsheet/index.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,40 @@ async function callFoo() {
4848
}
4949
```
5050

51+
## [Buffers](#buffers)
52+
53+
Class: Buffer
54+
55+
```
56+
Buffer.from(array)
57+
Buffer.from(arrayBuffer[, byteOffset[, length]])
58+
Buffer.from(buffer)
59+
Buffer.from(object[, offsetOrEncoding[, length]])
60+
Buffer.from(string[, encoding])
61+
Buffer.alloc(size[, fill[, encoding]])
62+
Buffer.allocUnsafe(size)
63+
Buffer.allocUnsafeSlow(size)
64+
```
65+
66+
Instance: buf
67+
68+
```
69+
buf.slice([start[, end]])
70+
buf.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])
71+
buf.copy(target[, targetStart[, sourceStart[, sourceEnd]]])
72+
buf.entries()
73+
buf.equals(otherBuffer)
74+
buf.fill(value[, offset[, end]][, encoding])
75+
buf.includes(value[, byteOffset][, encoding])
76+
buf.indexOf(value[, byteOffset][, encoding])
77+
buf.keys()
78+
buf.lastIndexOf(value[, byteOffset][, encoding])
79+
buf.length
80+
buf.toString([encoding[, start[, end]]])
81+
buf.values()
82+
buf.write(string[, offset[, length]][, encoding])
83+
```
84+
5185
## [Events](#events)
5286

5387
Class: events.EventEmitter

0 commit comments

Comments
 (0)