Memory helpers
Decide quando usar streaming e o tamanho dos chunks.
Assinatura
typescript
interface MemoryInfo {
used: number
available: number
limit: number
}
function getMemoryInfo(): MemoryInfo
function shouldUseStreaming(fileSize: number): boolean // typically > 10MB
function calculateChunkSize(
fileSize: number,
availableMemory?: number
): number // clamped ~1–5MBExample
typescript
import {
getMemoryInfo,
shouldUseStreaming,
calculateChunkSize,
compressStream,
compress,
} from '@pantanal/pixu'
const mem = getMemoryInfo()
console.log(mem.used, mem.limit)
if (shouldUseStreaming(file.size)) {
for await (const result of compressStream([file], {
quality: 0.8,
})) {
console.log(result.compressedSize)
}
} else {
await compress(file, { quality: 0.8 })
}
const chunk = calculateChunkSize(file.size, mem.available)