-
Notifications
You must be signed in to change notification settings - Fork 8
/
reference-source.js
40 lines (32 loc) · 940 Bytes
/
reference-source.js
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
'use strict'
const Status = require('./reference-status-enum')
class Source {
constructor () {
this.sink = null
}
bindSink (sink) {
// sink MUST be a data sink with a next(status, error, buffer, bytes) function
this.sink = sink
}
pull (error, buffer) {
// error MUST be null or an error
// buffer MUST be a Buffer
if (error) {
return this.sink.next(Status.error, error)
}
// if there was an error reading or processing the buffer...
const sourceError = new Error()
if (sourceError) {
return this.sink.next(Status.error, error)
}
// read into buffer
const more = true // If there is more to be read
const bytesWritten = 0 // Number of bytes written to the buffer
if (more) {
this.sink.next(Status.continue, null, buffer, bytesWritten)
} else {
this.sink.next(Status.end, null, buffer, bytesWritten)
}
}
}
module.exports = Source