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

utilium

Package Overview
Dependencies
Maintainers
0
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utilium - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

13

dist/requests.d.ts

@@ -16,2 +16,6 @@ export interface ResourceCacheOptions {

}
type CacheRange = {
start: number;
end: number;
};
export type RequestError = {

@@ -47,1 +51,10 @@ tag: 'status';

export declare function GET(url: string, options: RequestOptions, init?: RequestInit): Promise<Uint8Array>;
/**
* Synchronously gets a cached resource
* Assumes you pass valid start and end when using ranges
*/
export declare function getCached(url: string, options: RequestOptions): {
data: Uint8Array;
missing: CacheRange[];
};
export {};

@@ -173,1 +173,33 @@ /* Utilities for `fetch` when using range requests. It also allows you to handle errors easier */

}
/**
* Synchronously gets a cached resource
* Assumes you pass valid start and end when using ranges
*/
export function getCached(url, options) {
const cache = requestsCache.get(url);
/**
* @todo Make sure we have a size?
*/
if (!cache)
return { data: new Uint8Array(0), missing: [{ start: 0, end: options.size ?? 0 }] };
const { start = 0, end = cache.size } = options;
const data = new Uint8Array(end - start);
for (const region of cache.regions) {
if (region.offset + region.data.byteLength <= start)
continue;
if (region.offset >= end)
break;
for (const range of region.ranges) {
if (range.end <= start)
continue;
if (range.start >= end)
break;
const overlapStart = Math.max(range.start, start);
const overlapEnd = Math.min(range.end, end);
if (overlapStart >= overlapEnd)
continue;
data.set(region.data.subarray(overlapStart - region.offset, overlapEnd - region.offset), overlapStart - start);
}
}
return { data, missing: cache.missing(start, end) };
}

2

package.json
{
"name": "utilium",
"version": "1.2.0",
"version": "1.2.1",
"description": "Typescript utilities",

@@ -5,0 +5,0 @@ "funding": {

@@ -40,3 +40,3 @@ /* Utilities for `fetch` when using range requests. It also allows you to handle errors easier */

/** Regions used to reduce unneeded allocations. Think of sparse arrays. */
protected readonly regions: CacheRegion[] = [];
public readonly regions: CacheRegion[] = [];

@@ -253,1 +253,37 @@ public constructor(

}
/**
* Synchronously gets a cached resource
* Assumes you pass valid start and end when using ranges
*/
export function getCached(url: string, options: RequestOptions): { data: Uint8Array; missing: CacheRange[] } {
const cache = requestsCache.get(url);
/**
* @todo Make sure we have a size?
*/
if (!cache) return { data: new Uint8Array(0), missing: [{ start: 0, end: options.size ?? 0 }] };
const { start = 0, end = cache.size } = options;
const data = new Uint8Array(end - start);
for (const region of cache.regions) {
if (region.offset + region.data.byteLength <= start) continue;
if (region.offset >= end) break;
for (const range of region.ranges) {
if (range.end <= start) continue;
if (range.start >= end) break;
const overlapStart = Math.max(range.start, start);
const overlapEnd = Math.min(range.end, end);
if (overlapStart >= overlapEnd) continue;
data.set(region.data.subarray(overlapStart - region.offset, overlapEnd - region.offset), overlapStart - start);
}
}
return { data, missing: cache.missing(start, end) };
}
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