Skip to content

Commit

Permalink
fix(cli): support more biarny type files
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream authored and Red-Asuka committed Nov 15, 2024
1 parent 3d89c3a commit 7c09f73
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 4 deletions.
102 changes: 98 additions & 4 deletions cli/src/__tests__/utils/binaryFormats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,121 @@ import { expect, describe, it } from '@jest/globals'

describe('isSupportedBinaryFormatForMQTT', () => {
it('should return true for supported binary formats', () => {
const supportedFormats = ['.png', '.mp4', '.mp3', '.zip', '.exe', '.pdf']
const supportedFormats = [
// Common formats
'.png',
'.mp4',
'.mp3',
'.zip',
'.exe',
'.pdf',
// Network & Protocol formats
'.netp',
'.pcap',
'.pcapng',
'.cap',
'.dmp',
'.trace',
// Database formats
'.db',
'.sqlite',
'.mdb',
'.frm',
'.myd',
'.myi',
// IoT & Device formats
'.dat',
'.raw',
'.log',
'.blob',
'.hex',
'.rom',
'.fw',
// Custom protocol & data formats
'.pkt',
'.mpack',
'.parquet',
'.orc',
]
supportedFormats.forEach((format) => {
expect(isSupportedBinaryFormatForMQTT(format)).toBe(true)
})
})

it('should return false for unsupported binary formats', () => {
const unsupportedFormats = ['.txt', '.doc', '.xls', '.ppt', '.html', '.css']
const unsupportedFormats = [
// Text formats
'.txt',
'.md',
'.rtf',
// Document formats
'.doc',
'.docx',
'.xls',
'.xlsx',
'.ppt',
'.pptx',
// Web formats
'.html',
'.css',
'.js',
'.json',
'.xml',
// Source code formats
'.c',
'.cpp',
'.java',
'.py',
'.ts',
// Config formats
'.yml',
'.ini',
'.conf',
'.env',
]
unsupportedFormats.forEach((format) => {
expect(isSupportedBinaryFormatForMQTT(format)).toBe(false)
})
})

it('should be case-sensitive', () => {
expect(isSupportedBinaryFormatForMQTT('.PNG')).toBe(false)
expect(isSupportedBinaryFormatForMQTT('.png')).toBe(true)
const testCases = [
['.PNG', '.png'],
['.DB', '.db'],
['.NETP', '.netp'],
['.PCAP', '.pcap'],
['.HEX', '.hex'],
]

testCases.forEach(([upper, lower]) => {
expect(isSupportedBinaryFormatForMQTT(upper)).toBe(false)
expect(isSupportedBinaryFormatForMQTT(lower)).toBe(true)
})
})

it('should include all supported formats', () => {
supportedBinaryFormatsForMQTT.forEach((format) => {
expect(isSupportedBinaryFormatForMQTT(format)).toBe(true)
})
})

it('should handle format categories correctly', () => {
// Test by categories
const categories = {
image: ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.tif', '.tiff'],
video: ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.mpeg', '.3gp'],
audio: ['.mp3', '.wav', '.flac', '.aac', '.ogg', '.wma', '.m4a', '.m4p'],
compressed: ['.zip', '.gz', '.rar', '.tar', '.7z', '.bz2', '.xz', '.jar'],
network: ['.netp', '.pcap', '.pcapng', '.cap', '.dmp', '.trace'],
database: ['.db', '.sqlite', '.mdb', '.frm', '.myd', '.myi'],
device: ['.dat', '.raw', '.log', '.blob', '.hex', '.rom', '.fw'],
protocol: ['.pkt', '.mpack', '.parquet', '.orc'],
}

Object.values(categories)
.flat()
.forEach((format) => {
expect(isSupportedBinaryFormatForMQTT(format)).toBe(true)
})
})
})
23 changes: 23 additions & 0 deletions cli/src/utils/binaryFormats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ export const supportedBinaryFormatsForMQTT = [
'.img', // Binary file formats
'.pdf',
'.epub', // Binary document file formats
'.netp', // Network protocol binary format
'.pcap', // Packet capture
'.pcapng', // Next generation packet capture
'.cap', // Network capture
'.dmp', // Memory dump
'.trace', // Network trace
'.db', // Generic database
'.sqlite', // SQLite database
'.mdb', // Microsoft Access database
'.frm', // MySQL table definition
'.myd', // MySQL data
'.myi', // MySQL index
'.dat', // Generic data file
'.raw', // Raw data
'.log', // Binary log
'.blob', // Binary large object
'.hex', // Hex dump
'.rom', // ROM image
'.fw', // Firmware
'.pkt', // Packet data
'.mpack', // MessagePack data
'.parquet', // Parquet columnar storage
'.orc', // Optimized Row Columnar
]

const isSupportedBinaryFormatForMQTT = (fileExtname: string) => {
Expand Down

0 comments on commit 7c09f73

Please sign in to comment.