@expo/image-utils
Advanced tools
Comparing version 0.5.2-canary-20240719-83ee47b to 0.5.2-canary-20240814-ce0f7d5
@@ -10,6 +10,6 @@ "use strict"; | ||
const jimp_compact_1 = __importDefault(require("jimp-compact")); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const path_1 = __importDefault(require("path")); | ||
const stream_1 = __importDefault(require("stream")); | ||
const tempy_1 = __importDefault(require("tempy")); | ||
const temp_dir_1 = __importDefault(require("temp-dir")); | ||
const unique_string_1 = __importDefault(require("unique-string")); | ||
const util_1 = __importDefault(require("util")); | ||
@@ -21,2 +21,7 @@ // cache downloaded images into memory | ||
} | ||
function temporaryDirectory() { | ||
const directory = path_1.default.join(temp_dir_1.default, (0, unique_string_1.default)()); | ||
fs_extra_1.default.mkdirSync(directory); | ||
return directory; | ||
} | ||
async function downloadOrUseCachedImage(url) { | ||
@@ -36,11 +41,16 @@ if (url in cacheDownloadedKeys) { | ||
async function downloadImage(url) { | ||
const outputPath = tempy_1.default.directory(); | ||
const response = await (0, node_fetch_1.default)(url); | ||
const outputPath = temporaryDirectory(); | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`It was not possible to download image from '${url}'`); | ||
} | ||
if (!response.body) { | ||
throw new Error(`No response received from '${url}'`); | ||
} | ||
// Download to local file | ||
const streamPipeline = util_1.default.promisify(stream_1.default.pipeline); | ||
const localPath = path_1.default.join(outputPath, path_1.default.basename(stripQueryParams(url))); | ||
await streamPipeline(response.body, fs_extra_1.default.createWriteStream(localPath)); | ||
// Type casting is required, see: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/65542 | ||
const readableBody = stream_1.default.Readable.fromWeb(response.body); | ||
await streamPipeline(readableBody, fs_extra_1.default.createWriteStream(localPath)); | ||
// If an image URL doesn't have a name, get the mime type and move the file. | ||
@@ -47,0 +57,0 @@ const img = await jimp_compact_1.default.read(localPath); |
{ | ||
"name": "@expo/image-utils", | ||
"version": "0.5.2-canary-20240719-83ee47b", | ||
"version": "0.5.2-canary-20240814-ce0f7d5", | ||
"description": "A package used by Expo CLI for processing images", | ||
@@ -39,7 +39,7 @@ "main": "build/index.js", | ||
"jimp-compact": "0.16.1", | ||
"node-fetch": "^2.6.0", | ||
"parse-png": "^2.1.0", | ||
"resolve-from": "^5.0.0", | ||
"semver": "^7.6.0", | ||
"tempy": "0.3.0" | ||
"temp-dir": "~2.0.0", | ||
"unique-string": "~2.0.0" | ||
}, | ||
@@ -49,5 +49,4 @@ "devDependencies": { | ||
"@types/getenv": "^0.7.0", | ||
"@types/node-fetch": "^2.6.5", | ||
"@types/semver": "^6.0.0", | ||
"expo-module-scripts": "3.6.0-canary-20240719-83ee47b" | ||
"expo-module-scripts": "3.6.0-canary-20240814-ce0f7d5" | ||
}, | ||
@@ -57,3 +56,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "83ee47b5c89c7f1b1a5101189580eaf3555f5962" | ||
"gitHead": "ce0f7d5c7eaec2c8d06ee4e0dc0e58cd6c1612ed" | ||
} |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
77040
4
1093
1
+ Addedtemp-dir@~2.0.0
+ Addedunique-string@~2.0.0
+ Addedcrypto-random-string@2.0.0(transitive)
+ Addedtemp-dir@2.0.0(transitive)
+ Addedunique-string@2.0.0(transitive)
- Removednode-fetch@^2.6.0
- Removedtempy@0.3.0
- Removedcrypto-random-string@1.0.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedtemp-dir@1.0.0(transitive)
- Removedtempy@0.3.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedtype-fest@0.3.1(transitive)
- Removedunique-string@1.0.0(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)