mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 21:01:52 +00:00
This adds a new `unzipSync` function to the Bun runtime that allows
synchronous extraction of ZIP files. The implementation:
- Uses Zig's std.zip library for robust ZIP parsing
- Returns the first file found as a Uint8Array (simplified for initial version)
- Includes security measures to prevent directory traversal attacks
- Handles deflate and store compression methods
- Provides comprehensive error handling for malformed ZIP files
API Usage:
```javascript
import { unzipSync } from "bun";
const data = unzipSync(zipBuffer);
```
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
24 lines
621 B
JavaScript
24 lines
621 B
JavaScript
// Simple test to verify Bun.unzipSync is available
|
|
try {
|
|
const { unzipSync } = require("bun");
|
|
console.log("unzipSync function:", typeof unzipSync);
|
|
|
|
// Test with invalid input to see if it throws the right error
|
|
try {
|
|
unzipSync("not a buffer");
|
|
} catch (err) {
|
|
console.log("Expected error:", err.message);
|
|
}
|
|
|
|
// Test with empty buffer
|
|
try {
|
|
unzipSync(new Uint8Array(0));
|
|
} catch (err) {
|
|
console.log("Expected empty buffer error:", err.message);
|
|
}
|
|
|
|
console.log("Basic API test passed!");
|
|
} catch (err) {
|
|
console.error("API not available:", err.message);
|
|
process.exit(1);
|
|
} |