From 489e26d1b3c224beffba2649406efd83580989fe Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Tue, 18 Nov 2025 20:56:12 -0800 Subject: Replace hardcoded magic values with named constants and improve type safety Adds new constants for file format identifiers (FormatFILP), fork types (ForkTypeINFO), and platform identifiers (PlatformAMAC, PlatformMWIN) to improve code maintainability and readability. Changes FlatFileForkHeader.ForkType field from [4]byte to ForkType type alias for better compile-time type checking, matching the pattern used in ForkInfoList.Fork. --- hotline/file_resume_data.go | 5 +++++ hotline/file_wrapper.go | 8 ++++---- hotline/flattened_file_object.go | 4 ++-- hotline/transfer_test.go | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) (limited to 'hotline') diff --git a/hotline/file_resume_data.go b/hotline/file_resume_data.go index 80f5fe5..c9f27f6 100644 --- a/hotline/file_resume_data.go +++ b/hotline/file_resume_data.go @@ -32,6 +32,7 @@ type ForkInfoList struct { var ( ForkTypeDATA = ForkType{0x44, 0x41, 0x54, 0x41} // DATA: Data fork + ForkTypeINFO = ForkType{0x49, 0x4E, 0x46, 0x4F} // INFO: Information fork ForkTypeMACR = ForkType{0x4d, 0x41, 0x43, 0x52} // MACR: Mac resource fork ) @@ -45,7 +46,11 @@ func NewForkInfoList(b []byte) *ForkInfoList { } var ( + FormatFILP = [4]byte{0x46, 0x49, 0x4c, 0x50} // Flattened file format: "FILP" FormatRFLT = [4]byte{0x52, 0x46, 0x4C, 0x54} // File resume format: "RFLT" (?) + + PlatformAMAC = [4]byte{0x41, 0x4D, 0x41, 0x43} // Mac platform: "AMAC" + PlatformMWIN = [4]byte{0x4D, 0x57, 0x49, 0x4E} // Windows platform: "MWIN" ) func NewFileResumeData(list []ForkInfoList) *FileResumeData { diff --git a/hotline/file_wrapper.go b/hotline/file_wrapper.go index b6aff94..5ec99c3 100644 --- a/hotline/file_wrapper.go +++ b/hotline/file_wrapper.go @@ -227,7 +227,7 @@ func (f *fileWrapper) flattenedFileObject() (*flattenedFileObject, error) { } f.Ffo.FlatFileHeader = FlatFileHeader{ - Format: [4]byte{0x46, 0x49, 0x4c, 0x50}, // "FILP" + Format: FormatFILP, Version: [2]byte{0, 1}, ForkCount: [2]byte{0, 2}, } @@ -247,7 +247,7 @@ func (f *fileWrapper) flattenedFileObject() (*flattenedFileObject, error) { } } else { f.Ffo.FlatFileInformationFork = FlatFileInformationFork{ - Platform: [4]byte{0x41, 0x4D, 0x41, 0x43}, // "AMAC" TODO: Remove hardcode to support "AWIN" Platform (maybe?) + Platform: PlatformAMAC, // TODO: Remove hardcode to support "MWIN" Platform (maybe?) TypeSignature: [4]byte([]byte(ft.TypeCode)), CreatorSignature: [4]byte([]byte(ft.CreatorCode)), PlatformFlags: [4]byte{0, 0, 1, 0}, // TODO: What is this? @@ -263,12 +263,12 @@ func (f *fileWrapper) flattenedFileObject() (*flattenedFileObject, error) { } f.Ffo.FlatFileInformationForkHeader = FlatFileForkHeader{ - ForkType: [4]byte{0x49, 0x4E, 0x46, 0x4F}, // "INFO" + ForkType: ForkTypeINFO, DataSize: f.Ffo.FlatFileInformationFork.Size(), } f.Ffo.FlatFileDataForkHeader = FlatFileForkHeader{ - ForkType: [4]byte{0x44, 0x41, 0x54, 0x41}, // "DATA" + ForkType: ForkTypeDATA, DataSize: [4]byte{dataSize[0], dataSize[1], dataSize[2], dataSize[3]}, } f.Ffo.FlatFileResForkHeader = f.rsrcForkHeader() diff --git a/hotline/flattened_file_object.go b/hotline/flattened_file_object.go index 99ce204..7c0cd7d 100644 --- a/hotline/flattened_file_object.go +++ b/hotline/flattened_file_object.go @@ -45,7 +45,7 @@ type FlatFileInformationFork struct { func NewFlatFileInformationFork(fileName string, modifyTime [8]byte, typeSignature string, creatorSignature string) FlatFileInformationFork { return FlatFileInformationFork{ - Platform: [4]byte{0x41, 0x4D, 0x41, 0x43}, // "AMAC" TODO: Remove hardcode to support "AWIN" Platform (maybe?) + Platform: PlatformAMAC, // TODO: Remove hardcode to support "MWIN" Platform (maybe?) TypeSignature: [4]byte([]byte(typeSignature)), // TODO: Don't infer types from filename CreatorSignature: [4]byte([]byte(creatorSignature)), // TODO: Don't infer types from filename PlatformFlags: [4]byte{0, 0, 1, 0}, // TODO: What is this? @@ -128,7 +128,7 @@ func (ffif *FlatFileInformationFork) ReadNameSize() []byte { } type FlatFileForkHeader struct { - ForkType [4]byte // Either INFO, DATA or MACR + ForkType ForkType // Either INFO, DATA or MACR CompressionType [4]byte RSVD [4]byte DataSize [4]byte diff --git a/hotline/transfer_test.go b/hotline/transfer_test.go index 4aa142b..c915498 100644 --- a/hotline/transfer_test.go +++ b/hotline/transfer_test.go @@ -120,14 +120,14 @@ func Test_receiveFile(t *testing.T) { conn: func() io.Reader { testFile := flattenedFileObject{ FlatFileHeader: FlatFileHeader{ - Format: [4]byte{0x46, 0x49, 0x4c, 0x50}, // "FILP" + Format: FormatFILP, Version: [2]byte{0, 1}, ForkCount: [2]byte{0, 2}, }, FlatFileInformationForkHeader: FlatFileForkHeader{}, FlatFileInformationFork: NewFlatFileInformationFork("testfile.txt", [8]byte{}, "TEXT", "TEXT"), FlatFileDataForkHeader: FlatFileForkHeader{ - ForkType: [4]byte{0x4d, 0x41, 0x43, 0x52}, // DATA + ForkType: ForkTypeMACR, DataSize: [4]byte{0x00, 0x00, 0x00, 0x03}, }, } -- cgit