necessary 9.1.3 → 9.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -260,8 +260,7 @@ Note that the data returned when the "data" event is handled will be a byte arra
|
|
|
260
260
|
In the following example, the response is assumed to be binary data, an image say, and is piped straight to a file:
|
|
261
261
|
|
|
262
262
|
```
|
|
263
|
-
const {
|
|
264
|
-
{ createWriteStream } = require("fs");
|
|
263
|
+
const { createWriteStream } = require("fs");
|
|
265
264
|
|
|
266
265
|
get(host, uri, query, (error, response) => {
|
|
267
266
|
// Check for an error
|
|
@@ -270,9 +269,7 @@ get(host, uri, query, (error, response) => {
|
|
|
270
269
|
|
|
271
270
|
const writeStream = createWriteStream("...");
|
|
272
271
|
|
|
273
|
-
|
|
274
|
-
///
|
|
275
|
-
});
|
|
272
|
+
response.pipe(writeStream);
|
|
276
273
|
});
|
|
277
274
|
```
|
|
278
275
|
|
|
@@ -281,7 +278,7 @@ get(host, uri, query, (error, response) => {
|
|
|
281
278
|
In the following example the `queryStringFromQuery()` function from the HTTP utilities is used to encode the content. Note that the `content-type` and `content-length` headers must be set explicitly. Also note that there is no argument provided for the content itself, instead an instance of Node's [`Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable) class is created and piped to the request:
|
|
282
279
|
|
|
283
280
|
```
|
|
284
|
-
const {
|
|
281
|
+
const { Readable } = require("stream");
|
|
285
282
|
|
|
286
283
|
const content = queryStringFromQuery({
|
|
287
284
|
"name": "John Doe"
|
|
@@ -299,9 +296,7 @@ const content = queryStringFromQuery({
|
|
|
299
296
|
}),
|
|
300
297
|
readable = Readable.from(content);
|
|
301
298
|
|
|
302
|
-
|
|
303
|
-
///
|
|
304
|
-
});
|
|
299
|
+
readable.pope(request);
|
|
305
300
|
```
|
|
306
301
|
|
|
307
302
|
* The `delete()` function provides a means to make arbitrary HTTP requests. Its arguments are identical to the `post()` function bar an additional `method` argument that comes after the `query` argument. Unlike the `get()` and `post()` functions, in this case the `headers` argument is not optional.
|