Skip to content

Commit

Permalink
feat: add demo for streaming response to file
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerjt committed Feb 14, 2019
1 parent 5f517bd commit 5c8ae22
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
2 changes: 2 additions & 0 deletions demos/stream-response-to-file/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output/*
output/contents.txt
29 changes: 29 additions & 0 deletions demos/stream-response-to-file/index.js
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);
})
62 changes: 62 additions & 0 deletions demos/stream-response-to-file/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions demos/stream-response-to-file/package.json
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"
}
}

0 comments on commit 5c8ae22

Please sign in to comment.