Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): support more biarny type files #1808

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading