-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathevent-stream.node.txt
61 lines (50 loc) · 4 KB
/
event-stream.node.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
┏━━━━━━━━━━━━━━━━━━┓
┃ EVENT-STREAM ┃
┗━━━━━━━━━━━━━━━━━━┛
VERSION ==> #Node module (3.1.5)
#Deprecated
#Like map() functions for IOSTREAM
#"Chunks" are data separated by "data" events.
ES.though(...) #Same as THROUGH(...)
ES.map(FUNC(VAL, FUNC2)) #Same as THROUGH(FUNC(VAL)), except it is async: FUNC must call either:
# - FUNC2(null, VAL)
# - FUNC2(ERROR)
# - FUNC2(): drops the data (like a filter)
ES.from(...) #Same as FROM(...)
ES.split([REGEXP|STR[, UINT]]) #Break down chunks according to a delimiter (same args as STRING.split()) (déf: "\n")
#Also, if input is BUFFER, transforms it to STR. Doesn't work if input is OBJ.
#Maybe updated?
ES.join(STR) #Inserts a STR chunk between each chunk
ES.replace(...,STR) #Same as ES.split(...) then ES.join(STR)
ES.stringify() #If input is not STR, transform it to STR. Escape whitespaces and appends a newline.
ES.parse([OPTS]) #Same but doesn't escape whitespaces nor appends a newline.
#Input must be JSON.
#OPTS:
# - emitError BOOL (def: false): fire "error" event with ERROR on errors
ES.readable(FUNC(UINT, FUNC2)) #Creates a ISTREAM from FUNC():
# - this.emit("data", VAL) adds chunk VAL
# - this.emit("error", ERROR) can be called
# - FUNC() is iterated until this.emit("end"):
# - UINT is incrementing from 0
# - each iteration is finished by a call to FUNC2()
# - can use FUNC2(ERROR, VAL) instead of this.emit(...) then FUNC2()
# - this is the current ISTREAM
ES.readArray(ARR) #Creates a ISTREAM with a chunk for each element.
#data event handler takes same type as those elements.
ES.writeArray(FUNC(ERROR, ARR)) #Inverse
ES.duplex(ISTREAM, OSTREAM) #Combines as IOSTREAM. Doesn't redirect ISTREAM to OSTREAM, must have been done before,
#e.g. a CHILD_PROCESS.stdin and CHILD_PROCESS.stdout of a CHILD_PROCESS.exec()
ES.child(CHILD_PROCESS) #Same as ES.duplex(CHILD_PROCESS.stdin, CHILD_PROCESS.stdout)
ES.merge(OSTREAM, OSTREAM2) #Merge into one single OSTREAM3 (must not take input)
ES.pause() #Pauses/resumes current IOSTREAM, e.g.:
# IOSTREAM.pipe(ES.pause().pause())....pipe(ES.pause().resume())
ES.wait([FUNC(ERROR, STR|BUFFER)])#Waits for the end event, then emits all data as a single chunk STR|BUFFER
#Can get this chunk STR|BUFFER with FUNC()
STREAM-REDUCE(...) ##Similar to ARRAY.reduce(...) but here the VAL comes from each chunk, and the reduce()
##final return will be a single output chunk.
##Node module (1.0.3)
CONCAT-STREAM([OBJ, ]FUNC(VAL)) ##Returns a OSTREAM (not IOSTREAM, so can be piped in but not out) that returns concatenated
##chunks as a single VAL in FUNC(VAL).
##Type is according to OBJ.encoding STR (otherwise inferred), among "string", "buffer",
##"array", "uint8array" or "object"
##Node module (1.4.5)