diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-07-17 15:41:20 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-07-17 15:42:37 -0700 |
| commit | fd740bc499ebc6d3a381479316f74cdc736d02de (patch) | |
| tree | e77563ce0997e51debaec75c9f7a053759ca3a0a /hotline/file_header.go | |
| parent | 80aed6b19ff0b0927670e459ce5cc7a16ef047ec (diff) | |
Extensive refactor, quality of life enhancements
* Added ability to reload config, agreement, news, and user accounts without restarting the server by sending SIGHUP to the running process
* Added ability to use modern unix or windows line breaks in Agreement.txt and MessageBoard.txt instead of classic MacOS `\r` breaks.
* Extensive refactor towards swappable backends for the active server state
* Extensive refactored towards making the hotline package generic and re-usable for alternate server implemenations
* Fix bug where users whose accounts have been deleted would not be disconnected
Diffstat (limited to 'hotline/file_header.go')
| -rw-r--r-- | hotline/file_header.go | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/hotline/file_header.go b/hotline/file_header.go deleted file mode 100644 index b18229a..0000000 --- a/hotline/file_header.go +++ /dev/null @@ -1,46 +0,0 @@ -package hotline - -import ( - "encoding/binary" - "io" - "slices" -) - -type FileHeader struct { - Size [2]byte // Total size of FileHeader payload - Type [2]byte // 0 for file, 1 for dir - FilePath []byte // encoded file path - - readOffset int // Internal offset to track read progress -} - -func NewFileHeader(fileName string, isDir bool) FileHeader { - fh := FileHeader{ - FilePath: EncodeFilePath(fileName), - } - if isDir { - fh.Type = [2]byte{0x00, 0x01} - } - - encodedPathLen := uint16(len(fh.FilePath) + len(fh.Type)) - binary.BigEndian.PutUint16(fh.Size[:], encodedPathLen) - - return fh -} - -func (fh *FileHeader) Read(p []byte) (int, error) { - buf := slices.Concat( - fh.Size[:], - fh.Type[:], - fh.FilePath, - ) - - if fh.readOffset >= len(buf) { - return 0, io.EOF // All bytes have been read - } - - n := copy(p, buf[fh.readOffset:]) - fh.readOffset += n - - return n, nil -} |