-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add demo for streaming response to file
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
output/* | ||
output/contents.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { request } = require("../../packages/arcgis-rest-request"); | ||
const fs = require("fs"); | ||
const fetch = require('node-fetch'); | ||
require('isomorphic-form-data') | ||
|
||
const outFile = fs.createWriteStream(`./output/${Date.now()}.geojson`); | ||
const serviceUrl = "https://services.arcgis.com/uUvqNMGPm7axC2dD/arcgis/rest/services/Boating_Access_Sites/FeatureServer/0/query"; | ||
|
||
request(serviceUrl, { | ||
params: { | ||
where: "1=1", | ||
outSR: "4326", | ||
outFields: "*", | ||
returnGeometry: true, | ||
f: "geojson" | ||
}, | ||
stream: true, | ||
fetch: fetch | ||
}).then((resp) => { | ||
resp.pipe(outFile); | ||
resp.on('data', () => { | ||
console.log('Chunk received') | ||
}); | ||
resp.on('end', () => { | ||
console.log('Finished!'); | ||
}); | ||
}).catch((err) => { | ||
console.log(err); | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "stream-response-to-file", | ||
"version": "1.16.1", | ||
"description": "stream response to file with arcgis-rest-request", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Esri/arcgis-rest-js.git" | ||
}, | ||
"keywords": [ | ||
"arcgis", | ||
"rest", | ||
"stream", | ||
"node" | ||
], | ||
"author": "Joshua Tanner", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/Esri/arcgis-rest-js/issues" | ||
}, | ||
"homepage": "https://github.com/Esri/arcgis-rest-js#readme", | ||
"dependencies": { | ||
"isomorphic-form-data": "^2.0.0", | ||
"node-fetch": "^2.3.0" | ||
} | ||
} |