@travetto/asset
Advanced tools
Comparing version 4.0.6 to 4.0.7
{ | ||
"name": "@travetto/asset", | ||
"version": "4.0.6", | ||
"version": "4.0.7", | ||
"description": "Modular library for storing and retrieving binary assets", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -11,2 +11,3 @@ import fs from 'node:fs/promises'; | ||
import { StreamMeta } from '@travetto/model'; | ||
import { AppError } from '@travetto/base'; | ||
@@ -135,2 +136,25 @@ import { Asset } from './types'; | ||
} | ||
/** | ||
* Compute hash from a url | ||
*/ | ||
static async hashUrl(url: string, byteLimit = -1): Promise<string> { | ||
const hasher = crypto.createHash('sha256').setEncoding('hex'); | ||
const str = await fetch(url); | ||
if (!str.ok) { | ||
throw new AppError('Invalid url for hashing', 'data'); | ||
} | ||
const body = Readable.fromWeb(str.body!); | ||
let count = 0; | ||
for await (const chunk of body) { | ||
if (Buffer.isBuffer(chunk) || typeof chunk === 'string') { | ||
count += chunk?.length ?? 0; | ||
hasher.update(chunk); | ||
} | ||
if (count > byteLimit && byteLimit > 0) { | ||
body.destroy(); | ||
} | ||
} | ||
return hasher.end().read().toString(); | ||
} | ||
} |
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
27943
364