- incompleteFileSuffix = ".incomplete"
- infoForkNameTemplate = ".info_%s" // template string for info fork filenames
- rsrcForkNameTemplate = ".rsrc_%s" // template string for resource fork filenames
+ IncompleteFileSuffix = ".incomplete"
+ InfoForkNameTemplate = ".info_%s" // template string for info fork filenames
+ RsrcForkNameTemplate = ".rsrc_%s" // template string for resource fork filenames
)
// fileWrapper encapsulates the data, info, and resource forks of a Hotline file and provides methods to manage the files.
type fileWrapper struct {
fs FileStore
)
// fileWrapper encapsulates the data, info, and resource forks of a Hotline file and provides methods to manage the files.
type fileWrapper struct {
fs FileStore
path string // path to file directory
dataPath string // path to the file data fork
dataOffset int64
rsrcPath string // path to the file resource fork
infoPath string // path to the file information fork
incompletePath string // path to partially transferred temp file
path string // path to file directory
dataPath string // path to the file data fork
dataOffset int64
rsrcPath string // path to the file resource fork
infoPath string // path to the file information fork
incompletePath string // path to partially transferred temp file
-func newFileWrapper(fs FileStore, path string, dataOffset int64) (*fileWrapper, error) {
+func NewFileWrapper(fs FileStore, path string, dataOffset int64) (*fileWrapper, error) {
- rsrcPath: filepath.Join(dir, fmt.Sprintf(rsrcForkNameTemplate, fName)),
- infoPath: filepath.Join(dir, fmt.Sprintf(infoForkNameTemplate, fName)),
- incompletePath: filepath.Join(dir, fName+incompleteFileSuffix),
- ffo: &flattenedFileObject{},
+ rsrcPath: filepath.Join(dir, fmt.Sprintf(RsrcForkNameTemplate, fName)),
+ infoPath: filepath.Join(dir, fmt.Sprintf(InfoForkNameTemplate, fName)),
+ incompletePath: filepath.Join(dir, fName+IncompleteFileSuffix),
+ Ffo: &flattenedFileObject{},
- ForkType: [4]byte{0x4D, 0x41, 0x43, 0x52}, // "MACR"
- CompressionType: [4]byte{},
- RSVD: [4]byte{},
- DataSize: f.rsrcForkSize(),
+ ForkType: [4]byte{0x4D, 0x41, 0x43, 0x52}, // "MACR"
+ DataSize: f.rsrcForkSize(),
file, err := os.OpenFile(f.infoPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return nil, err
file, err := os.OpenFile(f.infoPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return nil, err
// Meta files include:
// * Partially uploaded file ending with .incomplete
// * Resource fork starting with .rsrc_
// * Info fork starting with .info
// Meta files include:
// * Partially uploaded file ending with .incomplete
// * Resource fork starting with .rsrc_
// * Info fork starting with .info
-// During move of the meta files, os.ErrNotExist is ignored as these files may legitimately not exist.
-func (f *fileWrapper) move(newPath string) error {
- err := f.fs.Rename(f.dataPath, filepath.Join(newPath, f.name))
+// During Move of the meta files, os.ErrNotExist is ignored as these files may legitimately not exist.
+func (f *fileWrapper) Move(newPath string) error {
+ err := f.fs.Rename(f.dataPath, filepath.Join(newPath, f.Name))
-// delete a fileWrapper and its associated metadata files if they exist
-func (f *fileWrapper) delete() error {
+// Delete a fileWrapper and its associated metadata files if they exist
+func (f *fileWrapper) Delete() error {
if errors.Is(err, fs.ErrNotExist) {
fileInfo, err = f.fs.Stat(f.incompletePath)
if err == nil {
if errors.Is(err, fs.ErrNotExist) {
fileInfo, err = f.fs.Stat(f.incompletePath)
if err == nil {
binary.BigEndian.PutUint32(dataSize, uint32(fileInfo.Size()-f.dataOffset))
ft, _ = fileTypeFromInfo(fileInfo)
}
} else {
binary.BigEndian.PutUint32(dataSize, uint32(fileInfo.Size()-f.dataOffset))
ft, _ = fileTypeFromInfo(fileInfo)
}
} else {
binary.BigEndian.PutUint32(dataSize, uint32(fileInfo.Size()-f.dataOffset))
ft, _ = fileTypeFromInfo(fileInfo)
}
binary.BigEndian.PutUint32(dataSize, uint32(fileInfo.Size()-f.dataOffset))
ft, _ = fileTypeFromInfo(fileInfo)
}
Format: [4]byte{0x46, 0x49, 0x4c, 0x50}, // "FILP"
Version: [2]byte{0, 1},
Format: [4]byte{0x46, 0x49, 0x4c, 0x50}, // "FILP"
Version: [2]byte{0, 1},
Platform: [4]byte{0x41, 0x4D, 0x41, 0x43}, // "AMAC" TODO: Remove hardcode to support "AWIN" 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?
CreateDate: mTime, // some filesystems don't support createTime
ModifyDate: mTime,
Platform: [4]byte{0x41, 0x4D, 0x41, 0x43}, // "AMAC" TODO: Remove hardcode to support "AWIN" 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?
CreateDate: mTime, // some filesystems don't support createTime
ModifyDate: mTime,
- binary.BigEndian.PutUint16(ns, uint16(len(f.name)))
- f.ffo.FlatFileInformationFork.NameSize = [2]byte(ns[:])
+ binary.BigEndian.PutUint16(ns, uint16(len(f.Name)))
+ f.Ffo.FlatFileInformationFork.NameSize = [2]byte(ns[:])
- f.ffo.FlatFileInformationForkHeader = FlatFileForkHeader{
- ForkType: [4]byte{0x49, 0x4E, 0x46, 0x4F}, // "INFO"
- CompressionType: [4]byte{},
- RSVD: [4]byte{},
- DataSize: f.ffo.FlatFileInformationFork.Size(),
+ f.Ffo.FlatFileInformationForkHeader = FlatFileForkHeader{
+ ForkType: [4]byte{0x49, 0x4E, 0x46, 0x4F}, // "INFO"
+ DataSize: f.Ffo.FlatFileInformationFork.Size(),
- f.ffo.FlatFileDataForkHeader = FlatFileForkHeader{
- ForkType: [4]byte{0x44, 0x41, 0x54, 0x41}, // "DATA"
- CompressionType: [4]byte{},
- RSVD: [4]byte{},
- DataSize: [4]byte{dataSize[0], dataSize[1], dataSize[2], dataSize[3]},
+ f.Ffo.FlatFileDataForkHeader = FlatFileForkHeader{
+ ForkType: [4]byte{0x44, 0x41, 0x54, 0x41}, // "DATA"
+ DataSize: [4]byte{dataSize[0], dataSize[1], dataSize[2], dataSize[3]},