diff --git a/demos/stream-response-to-file/.gitignore b/demos/stream-response-to-file/.gitignore new file mode 100644 index 0000000000..db3986b744 --- /dev/null +++ b/demos/stream-response-to-file/.gitignore @@ -0,0 +1,2 @@ +output/* +output/contents.txt \ No newline at end of file diff --git a/demos/stream-response-to-file/index.js b/demos/stream-response-to-file/index.js new file mode 100644 index 0000000000..5eb85a9346 --- /dev/null +++ b/demos/stream-response-to-file/index.js @@ -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); +}) \ No newline at end of file diff --git a/demos/stream-response-to-file/package-lock.json b/demos/stream-response-to-file/package-lock.json new file mode 100644 index 0000000000..e58a03c97f --- /dev/null +++ b/demos/stream-response-to-file/package-lock.json @@ -0,0 +1,62 @@ +{ + "name": "stream-response-to-file", + "version": "1.16.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "combined-stream": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", + "integrity": "sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==", + "requires": { + "delayed-stream": "1.0.0" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, + "form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.7", + "mime-types": "2.1.21" + } + }, + "isomorphic-form-data": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-form-data/-/isomorphic-form-data-2.0.0.tgz", + "integrity": "sha512-TYgVnXWeESVmQSg4GLVbalmQ+B4NPi/H4eWxqALKj63KsUrcu301YDjBqaOw3h+cbak7Na4Xyps3BiptHtxTfg==", + "requires": { + "form-data": "2.3.3" + } + }, + "mime-db": { + "version": "1.37.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.37.0.tgz", + "integrity": "sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg==" + }, + "mime-types": { + "version": "2.1.21", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz", + "integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==", + "requires": { + "mime-db": "1.37.0" + } + }, + "node-fetch": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.3.0.tgz", + "integrity": "sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==" + } + } +} diff --git a/demos/stream-response-to-file/package.json b/demos/stream-response-to-file/package.json new file mode 100644 index 0000000000..ff27d757d7 --- /dev/null +++ b/demos/stream-response-to-file/package.json @@ -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" + } +}