Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/asset

Package Overview
Dependencies
Maintainers
1
Versions
310
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/asset - npm Package Compare versions

Comparing version 4.0.9 to 4.0.10

2

package.json
{
"name": "@travetto/asset",
"version": "4.0.9",
"version": "4.0.10",
"description": "Modular library for storing and retrieving binary assets",

@@ -5,0 +5,0 @@ "keywords": [

@@ -137,33 +137,47 @@ import fs from 'node:fs/promises';

/**
* Compute hash from a url
* Fetch bytes from a url
*/
static async hashUrl(url: string, byteLimit = -1): Promise<string> {
const str = await fetch(url);
static async fetchBytes(url: string, byteLimit: number = -1): Promise<Buffer> {
const str = await fetch(url, {
headers: (byteLimit > 0) ? {
Range: `0-${byteLimit - 1}`
} : {}
});
if (!str.ok) {
throw new AppError('Invalid url for hashing', 'data');
}
const body = Readable.fromWeb(str.body!);
let count = 0;
const buffer: Buffer[] = [];
for await (const chunk of body) {
if (Buffer.isBuffer(chunk) || typeof chunk === 'string') {
if (Buffer.isBuffer(chunk)) {
buffer.push(chunk);
count += chunk.length;
} else if (typeof chunk === 'string') {
buffer.push(Buffer.from(chunk));
count += chunk.length;
}
for await (const chunk of Readable.fromWeb(str.body!)) {
if (Buffer.isBuffer(chunk)) {
buffer.push(chunk);
count += chunk.length;
} else if (typeof chunk === 'string') {
buffer.push(Buffer.from(chunk));
count += chunk.length;
}
if (count > byteLimit && byteLimit > 0) {
body.destroy();
}
if (count > byteLimit && byteLimit > 0) {
break;
}
}
try {
await str.body?.cancel();
} catch { }
return Buffer.concat(buffer, byteLimit <= 0 ? undefined : byteLimit);
}
/**
* Compute hash from a url
*/
static async hashUrl(url: string, byteLimit = -1): Promise<string> {
const hasher = crypto.createHash('sha256').setEncoding('hex');
const finalData = Buffer.concat(buffer, byteLimit <= 0 ? undefined : byteLimit);
const finalData = await this.fetchBytes(url, byteLimit);
return hasher.update(finalData).end().read().toString();
}
}
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