mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-09-01 01:57:55 +00:00
Always use raw bytes in file handles
Historically CC has supported two modes when working with file handles (and HTTP requests): - Text mode, which reads/write using UTF-8. - Binary mode, which reads/writes the raw bytes. However, this can be confusing at times. CC/Lua doesn't actually support unicode, so any characters beyond the 0.255 range were replaced with '?'. This meant that most of the time you were better off just using binary mode. This commit unifies text and binary mode - we now /always/ read the raw bytes of the file, rather than converting to/from UTF-8. Binary mode now only specifies whether handle.read() returns a number (and .write(123) writes a byte rather than coercing to a string). - Refactor the entire handle hierarchy. We now have an AbstractMount base class, which has the concrete implementation of all methods. The public-facing classes then re-export these methods by annotating them with @LuaFunction. These implementations are based on the Binary{Readable,Writable}Handle classes. The Encoded{..}Handle versions are now entirely removed. - As we no longer need to use BufferedReader/BufferedWriter, we can remove quite a lot of logic in Filesystem to handle wrapping closeable objects. - Add a new WritableMount.openFile method, which generalises openForWrite/openForAppend to accept OpenOptions. This allows us to support update mode (r+, w+) in fs.open. - fs.open now uses the new handle types, and supports update (r+, w+) mode. - http.request now uses the new readable handle type. We no longer encode the request body to UTF-8, nor decode the response from UTF-8. - Websockets now return text frame's contents directly, rather than converting it from UTF-8. Sending text frames now attempts to treat the passed string as UTF-8, rather than treating it as latin1.
This commit is contained in:
@@ -134,7 +134,7 @@ accepts blocks of DFPWM data and converts it to a list of 8-bit amplitudes, whic
|
||||
As mentioned above, [`speaker.playAudio`] accepts at most 128×1024 samples in one go. DFPMW uses a single bit for each
|
||||
sample, which means we want to process our audio in chunks of 16×1024 bytes (16KiB). In order to do this, we use
|
||||
[`io.lines`], which provides a nice way to loop over chunks of a file. You can of course just use [`fs.open`] and
|
||||
[`fs.BinaryReadHandle.read`] if you prefer.
|
||||
[`fs.ReadHandle.read`] if you prefer.
|
||||
|
||||
## Processing audio
|
||||
As mentioned near the beginning of this guide, PCM audio is pretty easy to work with as it's just a list of amplitudes.
|
||||
|
Reference in New Issue
Block a user