chore: dedup dead code + compress utility
Deploy FileDrop / deploy (push) Successful in 43s
Deploy FileDrop / deploy (push) Successful in 43s
- Hapus src/shared/utils/retry.ts (0 imports, dead) - Hapus src/shared/errors/index.ts (7 classes, 0 imports) - Hapus drizzle type exports dari schema.ts (tidak dipake) - Hapus src/config/index.ts, redirect 8 imports langsung ke env.ts - Ekstrak maybeCompressChunk ke shared/utils/compress.ts - Hapus duplikasi gzipSync di upload-file.ts + chunked-storage.ts - Lint clean, build clean
This commit is contained in:
1 parent
4c216b1d9f
commit
332853f398
15 files changed
+46
-304
No files matched your search
@@ -0,0 +1,32 @@
|
||||
/** Compression algorithm for chunked file storage. */
|
||||
export type CompressionAlgorithm = 'gzip' | null;
|
||||
|
||||
/**
|
||||
* Optionally compress a chunk with gzip.
|
||||
*
|
||||
* Compression is skipped if:
|
||||
* - The `compress` flag is false.
|
||||
* - The chunk is smaller than `compressionMinSizeBytes`.
|
||||
* - The compressed result is larger than the original.
|
||||
*
|
||||
* @param chunk - The raw chunk buffer.
|
||||
* @param compress - Whether compression is enabled.
|
||||
* @param compressionMinSizeBytes - Minimum chunk size to attempt compression.
|
||||
* @returns The (possibly compressed) bytes and the algorithm used.
|
||||
*/
|
||||
export const maybeCompressChunk = (
|
||||
chunk: Buffer,
|
||||
compress: boolean,
|
||||
compressionMinSizeBytes: number,
|
||||
): { bytes: Buffer; compressionAlgorithm: CompressionAlgorithm } => {
|
||||
if (!compress || chunk.byteLength < compressionMinSizeBytes) {
|
||||
return { bytes: chunk, compressionAlgorithm: null };
|
||||
}
|
||||
|
||||
const gzipped = Bun.gzipSync(chunk);
|
||||
if (gzipped.byteLength >= chunk.byteLength) {
|
||||
return { bytes: chunk, compressionAlgorithm: null };
|
||||
}
|
||||
|
||||
return { bytes: gzipped, compressionAlgorithm: 'gzip' };
|
||||
};
|
||||
Reference in new issue
Block a user