Comparing version 3.5.2 to 3.6.0
3.6.0 / 2022-12-05 | ||
================== | ||
**features** | ||
* [[`53d2c91`](http://github.com/node-modules/urllib/commit/53d2c919b7d370a866581b3924b9349f5da3bf9f)] - 👌 IMPROVE: Support old style readable stream (#423) (fengmk2 <<fengmk2@gmail.com>>) | ||
3.5.2 / 2022-11-25 | ||
@@ -3,0 +9,0 @@ ================== |
{ | ||
"name": "urllib", | ||
"version": "3.5.2", | ||
"version": "3.6.0", | ||
"publishConfig": { | ||
@@ -74,2 +74,3 @@ "tag": "latest" | ||
"@types/selfsigned": "^2.0.1", | ||
"@types/tar-stream": "^2.2.2", | ||
"@vitest/coverage-c8": "^0.23.4", | ||
@@ -84,4 +85,5 @@ "busboy": "^1.6.0", | ||
"selfsigned": "^2.0.1", | ||
"tar-stream": "^2.2.0", | ||
"typescript": "^4.8.3", | ||
"vitest": "^0.23.4" | ||
"vitest": "^0.25.3" | ||
}, | ||
@@ -88,0 +90,0 @@ "engines": { |
"use strict"; | ||
var _a, _b, _c; | ||
var _a, _b; | ||
var _BlobFromStream_stream, _BlobFromStream_type, _HttpClient_instances, _HttpClient_defaultArgs, _HttpClient_dispatcher, _HttpClient_requestInternal, _HttpClient_updateSocketInfo; | ||
@@ -29,8 +29,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
const FormData = undici_1.FormData !== null && undici_1.FormData !== void 0 ? undici_1.FormData : formdata_node_1.FormData; | ||
// impl isReadable on Node.js 14 | ||
const isReadable = (_a = stream_2.default.isReadable) !== null && _a !== void 0 ? _a : function isReadable(stream) { | ||
return stream && typeof stream.read === 'function'; | ||
}; | ||
// impl promise pipeline on Node.js 14 | ||
const pipelinePromise = (_c = (_b = stream_2.default.promises) === null || _b === void 0 ? void 0 : _b.pipeline) !== null && _c !== void 0 ? _c : function pipeline(...args) { | ||
const pipelinePromise = (_b = (_a = stream_2.default.promises) === null || _a === void 0 ? void 0 : _a.pipeline) !== null && _b !== void 0 ? _b : function pipeline(...args) { | ||
return new Promise((resolve, reject) => { | ||
@@ -263,2 +259,8 @@ (0, pump_1.default)(...args, (err) => { | ||
if (args.stream && !args.content) { | ||
// convert old style stream to new stream | ||
// https://nodejs.org/dist/latest-v18.x/docs/api/stream.html#readablewrapstream | ||
if ((0, utils_1.isReadable)(args.stream) && !(args.stream instanceof stream_1.Readable)) { | ||
debug('Request#%d convert old style stream to Readable', requestId); | ||
args.stream = new stream_1.Readable().wrap(args.stream); | ||
} | ||
args.content = args.stream; | ||
@@ -278,3 +280,3 @@ } | ||
} | ||
else if (args.files instanceof stream_1.Readable || isReadable(args.files)) { | ||
else if (args.files instanceof stream_1.Readable || (0, utils_1.isReadable)(args.files)) { | ||
uploadFiles.push(['file', args.files]); | ||
@@ -308,3 +310,3 @@ } | ||
} | ||
else if (file instanceof stream_1.Readable || isReadable(file)) { | ||
else if (file instanceof stream_1.Readable || (0, utils_1.isReadable)(file)) { | ||
const fileName = getFileName(file) || `streamfile${index}`; | ||
@@ -342,3 +344,3 @@ formData.append(field, new BlobFromStream(file, mime_types_1.default.lookup(fileName) || ''), fileName); | ||
|| Buffer.isBuffer(args.data) | ||
|| isReadable(args.data); | ||
|| (0, utils_1.isReadable)(args.data); | ||
if (isGETOrHEAD) { | ||
@@ -345,0 +347,0 @@ if (!isStringOrBufferOrReadable) { |
@@ -7,1 +7,2 @@ import { FixJSONCtlChars } from './Request'; | ||
export declare function performanceTime(startTime: number, now?: number): number; | ||
export declare function isReadable(stream: any): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.performanceTime = exports.globalId = exports.digestAuthHeader = exports.sleep = exports.parseJSON = void 0; | ||
exports.isReadable = exports.performanceTime = exports.globalId = exports.digestAuthHeader = exports.sleep = exports.parseJSON = void 0; | ||
const crypto_1 = require("crypto"); | ||
const stream_1 = require("stream"); | ||
const perf_hooks_1 = require("perf_hooks"); | ||
@@ -139,2 +140,16 @@ const JSONCtlCharsMap = { | ||
exports.performanceTime = performanceTime; | ||
function isReadable(stream) { | ||
if (typeof stream_1.Readable.isReadable === 'function') | ||
return stream_1.Readable.isReadable(stream); | ||
// patch from node | ||
// https://github.com/nodejs/node/blob/1287530385137dda1d44975063217ccf90759475/lib/internal/streams/utils.js#L119 | ||
// simple way https://github.com/sindresorhus/is-stream/blob/main/index.js | ||
return stream !== null | ||
&& typeof stream === 'object' | ||
&& typeof stream.pipe === 'function' | ||
&& stream.readable !== false | ||
&& typeof stream._read === 'function' | ||
&& typeof stream._readableState === 'object'; | ||
} | ||
exports.isReadable = isReadable; | ||
//# sourceMappingURL=utils.js.map |
@@ -1,2 +0,2 @@ | ||
var _a, _b, _c; | ||
var _a, _b; | ||
var _BlobFromStream_stream, _BlobFromStream_type, _HttpClient_instances, _HttpClient_defaultArgs, _HttpClient_dispatcher, _HttpClient_requestInternal, _HttpClient_updateSocketInfo; | ||
@@ -21,3 +21,3 @@ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { HttpAgent } from './HttpAgent.js'; | ||
import { parseJSON, sleep, digestAuthHeader, globalId, performanceTime } from './utils.js'; | ||
import { parseJSON, sleep, digestAuthHeader, globalId, performanceTime, isReadable } from './utils.js'; | ||
import symbols from './symbols.js'; | ||
@@ -27,8 +27,4 @@ import { initDiagnosticsChannel } from './diagnosticsChannel.js'; | ||
const FormData = FormDataNative !== null && FormDataNative !== void 0 ? FormDataNative : FormDataNode; | ||
// impl isReadable on Node.js 14 | ||
const isReadable = (_a = stream.isReadable) !== null && _a !== void 0 ? _a : function isReadable(stream) { | ||
return stream && typeof stream.read === 'function'; | ||
}; | ||
// impl promise pipeline on Node.js 14 | ||
const pipelinePromise = (_c = (_b = stream.promises) === null || _b === void 0 ? void 0 : _b.pipeline) !== null && _c !== void 0 ? _c : function pipeline(...args) { | ||
const pipelinePromise = (_b = (_a = stream.promises) === null || _a === void 0 ? void 0 : _a.pipeline) !== null && _b !== void 0 ? _b : function pipeline(...args) { | ||
return new Promise((resolve, reject) => { | ||
@@ -260,2 +256,8 @@ pump(...args, (err) => { | ||
if (args.stream && !args.content) { | ||
// convert old style stream to new stream | ||
// https://nodejs.org/dist/latest-v18.x/docs/api/stream.html#readablewrapstream | ||
if (isReadable(args.stream) && !(args.stream instanceof Readable)) { | ||
debug('Request#%d convert old style stream to Readable', requestId); | ||
args.stream = new Readable().wrap(args.stream); | ||
} | ||
args.content = args.stream; | ||
@@ -262,0 +264,0 @@ } |
@@ -7,1 +7,2 @@ import { FixJSONCtlChars } from './Request'; | ||
export declare function performanceTime(startTime: number, now?: number): number; | ||
export declare function isReadable(stream: any): boolean; |
import { randomBytes, createHash } from 'crypto'; | ||
import { Readable } from 'stream'; | ||
import { performance } from 'perf_hooks'; | ||
@@ -131,2 +132,15 @@ const JSONCtlCharsMap = { | ||
} | ||
export function isReadable(stream) { | ||
if (typeof Readable.isReadable === 'function') | ||
return Readable.isReadable(stream); | ||
// patch from node | ||
// https://github.com/nodejs/node/blob/1287530385137dda1d44975063217ccf90759475/lib/internal/streams/utils.js#L119 | ||
// simple way https://github.com/sindresorhus/is-stream/blob/main/index.js | ||
return stream !== null | ||
&& typeof stream === 'object' | ||
&& typeof stream.pipe === 'function' | ||
&& stream.readable !== false | ||
&& typeof stream._read === 'function' | ||
&& typeof stream._readableState === 'object'; | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -31,3 +31,3 @@ import { EventEmitter } from 'events'; | ||
import { HttpClientResponseMeta, HttpClientResponse, ReadableWithMeta, BaseResponseMeta, SocketInfo } from './Response'; | ||
import { parseJSON, sleep, digestAuthHeader, globalId, performanceTime } from './utils'; | ||
import { parseJSON, sleep, digestAuthHeader, globalId, performanceTime, isReadable } from './utils'; | ||
import symbols from './symbols'; | ||
@@ -38,6 +38,2 @@ import { initDiagnosticsChannel } from './diagnosticsChannel'; | ||
const FormData = FormDataNative ?? FormDataNode; | ||
// impl isReadable on Node.js 14 | ||
const isReadable = stream.isReadable ?? function isReadable(stream: any) { | ||
return stream && typeof stream.read === 'function'; | ||
}; | ||
// impl promise pipeline on Node.js 14 | ||
@@ -320,2 +316,8 @@ const pipelinePromise = stream.promises?.pipeline ?? function pipeline(...args: any[]) { | ||
if (args.stream && !args.content) { | ||
// convert old style stream to new stream | ||
// https://nodejs.org/dist/latest-v18.x/docs/api/stream.html#readablewrapstream | ||
if (isReadable(args.stream) && !(args.stream instanceof Readable)) { | ||
debug('Request#%d convert old style stream to Readable', requestId); | ||
args.stream = new Readable().wrap(args.stream); | ||
} | ||
args.content = args.stream; | ||
@@ -322,0 +324,0 @@ } |
import { randomBytes, createHash } from 'crypto'; | ||
import { Readable } from 'stream'; | ||
import { performance } from 'perf_hooks'; | ||
@@ -144,1 +145,14 @@ import { FixJSONCtlChars } from './Request'; | ||
} | ||
export function isReadable(stream: any) { | ||
if (typeof Readable.isReadable === 'function') return Readable.isReadable(stream); | ||
// patch from node | ||
// https://github.com/nodejs/node/blob/1287530385137dda1d44975063217ccf90759475/lib/internal/streams/utils.js#L119 | ||
// simple way https://github.com/sindresorhus/is-stream/blob/main/index.js | ||
return stream !== null | ||
&& typeof stream === 'object' | ||
&& typeof stream.pipe === 'function' | ||
&& stream.readable !== false | ||
&& typeof stream._read === 'function' | ||
&& typeof stream._readableState === 'object'; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
262295
3504
18