mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-11 10:36:07 +00:00
fix: handle both gzipped and plain text package list responses
- Added magic number detection (0x1f 0x8b) to identify gzipped content - Removed unnecessary gunzip options that were causing decompression issues - Added fallback to treat non-gzipped responses as plain text
This commit is contained in:
@@ -30,13 +30,12 @@ export class DebianPackageFetcher {
|
|||||||
const buffer = await response.arrayBuffer()
|
const buffer = await response.arrayBuffer()
|
||||||
const compressed = new Uint8Array(buffer)
|
const compressed = new Uint8Array(buffer)
|
||||||
|
|
||||||
// Decompress using Node.js zlib with proper error handling
|
// Decompress if input is gzipped (magic 0x1f 0x8b); otherwise treat as plain text
|
||||||
|
let text: string
|
||||||
|
if (compressed.length >= 2 && compressed[0] === 0x1f && compressed[1] === 0x8b) {
|
||||||
const { gunzip } = await import('zlib')
|
const { gunzip } = await import('zlib')
|
||||||
const decompressed = await new Promise<Buffer>((resolve, reject) => {
|
const decompressed = await new Promise<Buffer>((resolve, reject) => {
|
||||||
gunzip(compressed, {
|
gunzip(compressed, (err, result) => {
|
||||||
finishFlush: 1, // Z_SYNC_FLUSH
|
|
||||||
windowBits: 15 + 16 // Enable gzip header decoding
|
|
||||||
}, (err, result) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Gunzip error:', err)
|
console.error('Gunzip error:', err)
|
||||||
reject(err)
|
reject(err)
|
||||||
@@ -45,8 +44,10 @@ export class DebianPackageFetcher {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
text = decompressed.toString('utf-8')
|
||||||
const text = decompressed.toString('utf-8')
|
} else {
|
||||||
|
text = Buffer.from(compressed).toString('utf-8')
|
||||||
|
}
|
||||||
const packages = this.parseDebianPackageList(text)
|
const packages = this.parseDebianPackageList(text)
|
||||||
|
|
||||||
console.log(`📊 Parsed ${packages.length} Debian packages`)
|
console.log(`📊 Parsed ${packages.length} Debian packages`)
|
||||||
@@ -76,13 +77,12 @@ export class DebianPackageFetcher {
|
|||||||
const buffer = await response.arrayBuffer()
|
const buffer = await response.arrayBuffer()
|
||||||
const compressed = new Uint8Array(buffer)
|
const compressed = new Uint8Array(buffer)
|
||||||
|
|
||||||
// Decompress using Node.js zlib with proper error handling
|
// Decompress if input is gzipped (magic 0x1f 0x8b); otherwise treat as plain text
|
||||||
|
let text: string
|
||||||
|
if (compressed.length >= 2 && compressed[0] === 0x1f && compressed[1] === 0x8b) {
|
||||||
const { gunzip } = await import('zlib')
|
const { gunzip } = await import('zlib')
|
||||||
const decompressed = await new Promise<Buffer>((resolve, reject) => {
|
const decompressed = await new Promise<Buffer>((resolve, reject) => {
|
||||||
gunzip(compressed, {
|
gunzip(compressed, (err, result) => {
|
||||||
finishFlush: 1, // Z_SYNC_FLUSH
|
|
||||||
windowBits: 15 + 16 // Enable gzip header decoding
|
|
||||||
}, (err, result) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Gunzip error:', err)
|
console.error('Gunzip error:', err)
|
||||||
reject(err)
|
reject(err)
|
||||||
@@ -91,8 +91,10 @@ export class DebianPackageFetcher {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
text = decompressed.toString('utf-8')
|
||||||
const text = decompressed.toString('utf-8')
|
} else {
|
||||||
|
text = Buffer.from(compressed).toString('utf-8')
|
||||||
|
}
|
||||||
const packages = this.parseUbuntuPackageList(text)
|
const packages = this.parseUbuntuPackageList(text)
|
||||||
|
|
||||||
console.log(`📊 Parsed ${packages.length} Ubuntu packages`)
|
console.log(`📊 Parsed ${packages.length} Ubuntu packages`)
|
||||||
|
|||||||
Reference in New Issue
Block a user