New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fetch-filecache-for-crawling

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-filecache-for-crawling - npm Package Compare versions

Comparing version 4.1.0 to 5.0.0

examples/example-reset.js

8

examples/example-etag.js

@@ -13,7 +13,6 @@ /**

async function run() {
const etag = '"5421-55a8e11cc2280"';
const etag = '"5421-55a8e11cc2280-gzip"';
console.log(`Fetch https://www.w3.org/TR/2012/REC-hr-time-20121217/ with etag ${etag}`);
let resp = await fetch('https://www.w3.org/TR/2012/REC-hr-time-20121217/', {
refresh: 'once', // Needed because of invalid cache semantics in W3C servers
compress: false,
refresh: 'once',
headers: {

@@ -28,4 +27,3 @@ 'If-None-Match': etag

resp = await fetch('https://www.w3.org/TR/2012/REC-hr-time-20121217/', {
refresh: 'force',
compress: false,
refresh: 'force'
});

@@ -32,0 +30,0 @@ console.log(`Received HTTP status ${resp.status} with etag ${resp.headers.get('etag')}`)

@@ -11,5 +11,3 @@ /**

const filenamifyUrl = require('filenamify-url');
const baseFetch = require('node-fetch');
const Response = require('node-fetch').Response;
const rimraf = require('rimraf');
const { rimraf } = require('rimraf');
const path = require('path');

@@ -162,3 +160,3 @@ const fs = require('fs');

*/
async function fetch(url, options) {
async function cacheFetch(url, options) {
// We may modify request options in place, let's make a shallow copy

@@ -208,3 +206,3 @@ options = Object.assign({}, options);

cacheFolderReset[config.cacheFolder] = true;
await rimraf(config.cacheFolder + '/*');
await rimraf(config.cacheFolder + '/*', { glob: true });
}

@@ -447,3 +445,3 @@

log('fetch and save response to cache');
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
let writable = fs.createWriteStream(cacheFilename);

@@ -457,3 +455,13 @@ writable.on('close', _ => {

writable.on('error', reject);
response.body.pipe(writable);
const reader = response.body.getReader();
while (true) {
const chunk = await reader.read();
if (chunk.done) {
writable.close();
break;
}
else {
writable.write(chunk.value);
}
}
});

@@ -483,3 +491,3 @@ }

try {
return await baseFetch(url, options);
return await fetch(url, options);
}

@@ -540,5 +548,5 @@ catch (err) {

module.exports = fetch;
module.exports = cacheFetch;
module.exports.setParameter = function (name, value) {
globalConfig[name] = value;
}
{
"name": "fetch-filecache-for-crawling",
"version": "4.1.0",
"version": "5.0.0",
"description": "Implementation of a `fetch` that extends the implementation from `node-fetch` to add an HTTP cache using a local cache folder for crawling purpose.",

@@ -19,9 +19,8 @@ "main": "fetch-filecache.js",

"engines": {
"node": ">=12.0.0"
"node": ">=18.0.0"
},
"dependencies": {
"filenamify-url": "^2.1.2",
"node-fetch": "^2.6.0",
"rimraf": "^3.0.2"
"rimraf": "^5.0.1"
}
}
# Implementation of fetch with a file-based HTTP cache for crawling purpose
Node.js module that exports a `fetch` function that extends the implementation
from `node-fetch` to add an HTTP cache using a local cache folder.
of Node.js native `fetch` to add an HTTP cache using a local cache folder.

@@ -30,3 +30,3 @@ The code was developed for a particular scenario with specific requirements in

Run `npm install fetch-filecache-for-crawling`
Run `npm install fetch-filecache-for-crawling`.

@@ -33,0 +33,0 @@ ## Usage

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc