-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.hbs
More file actions
67 lines (56 loc) · 2.05 KB
/
README.hbs
File metadata and controls
67 lines (56 loc) · 2.05 KB
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
62
63
64
65
66
67

[](https://travis-ci.org/node-dmr/dmr-source)
[](https://coveralls.io/github/node-dmr/dmr-source)
[](https://www.npmjs.org/package/dmr-source)
[](https://www.npmjs.org/package/dmr-source)
# What's dmr-source
Dmr-Source provides unified methods to achieve stream of data sources, such as local / remote (http / ftp) ...
- [x] Source
- [x] FileSource
- [x] HttpSource
- [x] FtpSource
- [x] MultiSource
- [ ] SftpSource
- [ ] HadoopSource
# Usage
Get file from ftp server to local
```Typescript
const fs = new FtpSource({
host: "127.0.0.1",
path: "/source-ftp-test.dict",
port: 21,
});
const writer = new FileSource().createWritableStream({path: "/home/work/a.log"});
fs.createReadableStream().pipe(writer);
```
Copy big file by FileSource
```Typescript
const fs = new FileSource({encoding: "utf8"});
const reader = fs.createReadableStream({path: "/home/work/a.log"});
const writer =fs.createWritableStream((option) => {
option.path = "/home/work/b.log";
return option;
});
reader.pipe(writer);
```
Link readables to one readable stream
```Typescript
const stream1 = new HttpSource({host: "localhost", path: "/a.log"}).createReadableStream();
const stream2 = new FileSource({host: "localhost", path: "/b.log"}).createReadableStream();
const ms = new MultiSource().add(stream1).add(stream2).add(() => {
return new FileSource({host: "localhost", path: "/c.log"}).createReadableStream();
});
ms.createReadableStream().on("data", (chunk) => console.log(chunk));
```
Events
```Typescript
const stream = new HttpSource({host: "localhost", path: "/404.page", timeout: 6000})
.createReadableStream();
stream.on("error", (err) => {
console.log("should be 404 error", err);
});
stream.on("end", (err) => {
console.log("never arrive end");
});
```
# API