Skip to content

Commit 89cc920

Browse files
committed
Add stream example
1 parent 9f0e174 commit 89cc920

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

examples/stream.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
var got = require('got')
4+
var toUTF8 = require('..')
5+
6+
const url = process.argv[2]
7+
8+
let str = ''
9+
let contentType
10+
11+
got
12+
.stream(url)
13+
.on('response', res => (contentType = res.headers['content-type']))
14+
.on('data', buffer => (str += toUTF8(buffer, contentType)))
15+
.on('end', function () {
16+
console.log(str)
17+
})

0 commit comments

Comments
 (0)