dstructures Flashcards

1
Q

js: a blob is

A

the binary string of an entire file stored in ram. Like a file stored fully in ram.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

cs: a binary is

A

a string sequence of 0s or 1s that make up any file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

cs: a bit is

A

a string, either 0 or 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

cs: a byte is

A

a string of 8 bits (which are either 0 or 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

cs: All digital media (text, pictures, videos, etc) is

A

stored as bits at the lowest level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

cs: bit stands for

A

binary digit

https://medium.freecodecamp.org/do-you-want-a-better-understanding-of-buffer-in-node-js-check-this-out-2e29de2968e8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

cs: To save a number, a computer must first

A

convert it to its binary representation whic is the same number written in base-2. So, 3 becomes 11.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

cs: To save a letter, a computer must first

A

convert it to a number (using the character to number dictionary called character set, usually unicode), and then convert that number into binary aka base-2.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

cs: To know which letter corresponds with which number, a computer must check the

A

character to number dictionary, aka, character set, usually unicode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

cs: The most common character set is

A

Unicode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

cs: A character set is

A

a character to number dictionary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

cs: A character encoding is a

A

set of rules about how to format the binary you created from a letter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

cs: The most popular character encoding it

A

UTF-8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

cs: The UTF-8 rules about converting a character to a byte force you to

A

save into a bytes (8 digits). When the letter’s number’s base-2 version is less than 8 digits, you must add 0s to the beginning of the byte.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

cs: Chunks are kinda big

A

a large text file can have just 2 chunks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

js: During a stream, node automatically creates

A

an internal buffer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

cs: The three types of stream are

A

readable, writable and duplex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

cs: Some common uses of streams are

A

reading and writing to disk, sending response to client from server, console.log()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

cs: In http streams, usually

A

an internal buffer in ram gets filled with bytes, and then when the internal buffer is full it sends a chunk to the client and asks for new data.

https: //www.youtube.com/watch?v=GpGTYp_G9VE
https: //www.youtube.com/watch?v=YpVDaVufDVU

20
Q

cs: streams emit

A

events, like data and end

21
Q

node: To write a script that echos back whatever you type into the console, type

A

process. stdin.pipe(process.stdout)

process. stdout is a callback function that gets the process.stdin return as a parameter

22
Q

cs: To start a stream’s transfer of bits, type

A

myStream.read()

23
Q

cs: A buffer is

A

an object that holds binary string
held in ram
fills with data up to allocated limit

https: //nodejs.org/api/stream.html#stream_buffering
https: //hackernoon.com/https-medium-com-amanhimself-converting-a-buffer-to-json-and-utf8-strings-in-nodejs-2150b1e3de57
https: //allenkim67.github.io/programming/2016/05/17/nodejs-buffer-tutorial.html

24
Q

js: A stream is basically an

A

object that spits out bytes of data continuously into an internal buffer which fills up to its byte limit, and then sends all that data as a chunk to a stream receiver, and asks for next data.

The stream runs .emit(‘data’, payload) whenever it wants to send data and then your event handler runs with that data payload as a param.

https://medium.freecodecamp.org/node-js-streams-everything-you-need-to-know-c9141306be93

To make a stream stop sending data

https://youtu.be/lQAV3bPOYHo?t=168

25
Q

cs: in -Buffer 02 04 06 08 0a 0c 0e 10> each number represents

A

a byte translated into hexadecimal

26
Q

cs: the size of a buffer is a count of it’s

A

bytes

27
Q

cs: To concatenate many blobs together, type

A

add them all to an array
let myBobs = [Blob1, Blob2, Blob3]

and then
let fullBlob = new Blob(myBobs, {type: 'video/webm'})

Set whatever type you want

28
Q

cs: setting a blob to application/octet-stream means

A

it is arbitrary binary data

https://stackoverflow.com/questions/20508788/do-i-need-content-type-application-octet-stream-for-file-download

29
Q

cs: To end a running stream, you

A

push null into the stream
this.push(null)

https://gist.github.com/joyrexus/10026630

30
Q

cs: The end event from readable streams is important because it

A

tells the internal buffer thats not full yet to send the remaining data.

31
Q

exp: In express, the response object is a stream, so

A

you can pipe data to it, and it will send all the chunks.
file.pipe(res)
or
res.write(‘string’)

https: //medium.com/@daspinola/video-stream-with-node-js-and-html5-320b3191a6b6
https: //stackoverflow.com/questions/38788721/how-do-i-stream-response-in-express

32
Q

js: when you .push() to a readable stream, but the consumer is not ready

A

the data gets buffered

https://github.com/substack/stream-handbook

33
Q

js: To write a readable stream, type

A

var Readable = require(‘stream’).Readable;

var myStream = new Readable;
myStream.push(‘beep ‘);
myStream.push(‘boop\n’);
myStream.push(null);

myStream.pipe(process.stdout);

34
Q

js: To only start pushing data onto a stream after the consumer calls read, type

A
var Readable = require('stream').Readable;
var myStream = Readable();
myStream._read = function () {
    myStream.push('beep ');
    myStream.push('boop\n');
    myStream.push(null);
};

myStream.pipe(process.stdout);

35
Q

cs: Converting a file to base-64 means

A

encoding it with an algorithm.

https: //www.youtube.com/watch?v=8qkxeZmKmOY
https: //www.youtube.com/watch?v=eUjVcUiNbD4

36
Q

cs: The streams data event gets triggered when

A

its buffer gets full and sends a chunk

myStream.on(‘data’, (chunk)=>{
console.log(‘chunk sent’)
})

37
Q

js: To convert a Buffer to json, type

A

JSON.stringify(bufferName);

=> {type: ‘Buffer’, data: [12,34,45…]}

https://hackernoon.com/https-medium-com-amanhimself-converting-a-buffer-to-json-and-utf8-strings-in-nodejs-2150b1e3de57

38
Q

js: To convert a node Buffer object to a javascript ArrayBuffer object

A

https://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer

39
Q

Node: Once a buffers size is set

A

it cannot be changed

40
Q

js: A buffer is a lot like a

A

blob

41
Q

js: What this is basically doing is myReadableStream.pipe(myWritableStream)

A
myReadableStream.on('data', (chunk) => {
  myWritableStream.write(chunk);
});
myReadableStream.on('end', () => {
  myWritableStream.end();
});
42
Q

js: To create an event emitter, type

A

Note:
Event emitters need chainable .on() functions

https: //www.youtube.com/watch?v=X-AhceP6jpA (apparently this guy made mistakes. Maybe use:
https: //gist.github.com/mudge/5830382 spinmutoli’s design

43
Q

js: to convert a readable stream into a blob, type

A
let chunks = []
myStream.on('data', function (chunk) {
  chunks.push(chunk)
})
.on('end', function () {
  let blob = new Blob(chunks, { type: 'myType' })
})
44
Q

js: To convert a function to a promise and rely on its return for another function, type

A
//  bad
const slowFunc = () => {
  setTimeout(() => {return 'string'}, 5000)
}
const reliesOnSlowFunc = () => {
  console.log(slowFunc() + 'string')
}

reliesOnSlowFunc()
undefinedstring

//  good
const slowFunc = () => {
    return new Promise((resolve, reject) => {
      setTimeout(() => resolve('string') , 5000)
  })
}

const reliesOnSlowFunc = () => {
slowFunc().then((res) => console.log(res + ‘string’))
}
> stringstring // after 5 seconds

Note: The last function is always a side effect function. If you rely on the return, then it must be a promise.

45
Q
i need to learn this Promise.resolve(path.join(path1, path2)).then(function(path) {
   // use the result here
});
A

https://stackoverflow.com/questions/36826592/what-is-the-best-way-to-wrap-synchronous-functions-in-to-a-promise