pradosoft / prado

Prado - Component Framework for PHP
Other
187 stars 70 forks source link

TDataReader and TDataWriter #904

Open belisoful opened 1 year ago

belisoful commented 1 year ago

We have a TTextWriter but we don't have any solid core classes for reading and writing streams of digital bit/byte-based data. In the world of XML, HTML, and XHTML such formats may seem extraneous. However there are many data that is written and read in bits rather than text encoded.

Reading and writing IPTC, EXIF, JPEG APP tags, and other digital formats does need such classes. No doubt there are other applications for such utility... including streaming data over TCP/UDP, and other digital formed data.

I have these done already and they do a few extra things like read half floats and mini floats that typical php and PHP Readers/Writers do not do. It has push/pop for offset saving and restoring and sectioning for isolating a portion of a file as if it were its own file. The sectioning is useful for designating a portion of the file (start offset and length) as IPTC encoded data and it will start the "file offset" at the start of the IPTC block, and act like its the end of the file at the end of its length.

Necessity is often one of the greatest sources of inspiration.

belisoful commented 1 year ago

more utility is needed than just TDataReader and TDataWriter.

TDataStream - encapsulates a PHP Stream, standardizes stream behavior (mainly writing). TDataReader- reads binary data in a specified endian TDataWriter - writes binary data in a specific endian TFileReader - initialization but with a file path. a slightly more specific TDataReader TFileWriter - initialization but with a file path. a slightly more specific TDataWriter

TBitReader - for reading a specific number of bits at a time. TBitWriter - for writing a specific number of bits at a time.

TDataAllocation - structured memory allocation functionality

TLZWCompressor - A common, effective, and fast compression algorithm (with expired patent) TPackBitsCompressor - used by TIFF.

belisoful commented 1 year ago

TDataStream may be able to handle files is being designed for files, but I think sockets will fit and can be handled as well. Sending binary data by socket through TDataWriter would be utilitarian.

belisoful commented 1 year ago

This is a more interesting issue that I initially figured. Reading and writing binary numbers in a stream could mean the steam is a resource, file, socket, I/O pipe, or process pipes each with their own slighting different open and close function. Each are using fread and fwrite to receive and send data.

This adds a great abstraction layer to interprocess communication, which we may need if cron is going to spin off each cron job as its own process at some point.

I feel like I have to do at least 4 iterations of anything I do to make the work up to date with current PRADO standards. lol. eg. The very short function and miner tweak to support composer plugins was the reduction of 1.5 years of work with countless classes for making PRADO plugins before composer was a thing. in revisiting it that was how it was reduced to basically one function to support composer plugins.

belisoful commented 1 year ago

BTW, this is turning into a general IO package. It's looking awesome. It adds support for binary IO on StdIn, StdOut, Input, Output, StdErr, Temp Files (3 forms, including a retainable temp), Sockets, Temp-Memory, , Pipes, Processes, Files, and downloaded URLs via fopen.

I am hoping this unlocks more potential and utility of PRADO. Other packages like ASP and JAVA have IO and network classes.

this is core functionality of an asset and publishing those assets. So, before we address publishing an asset, we need to be able to read it, write it, and process it properly. I also like the standardization of reading and writing so many sources and sinks.

and, as stated, bit reader/writer, and LZW and packbits compression.

belisoful commented 1 year ago

Found another bug in PHPStan: https://github.com/phpstan/phpstan/issues/9386

Documented here: https://phpstan.org/r/84a3c6f1-9649-4f59-8a1b-ae9d8af656eb

A trait is being used by two classes, but only one class has specific properties. The class is checked for and properties accessed. The problem is that the second class using the trait, PHPStan thinks is also executing on the class properties. The class with the properties is being checked and the class without the properties is excluded. PHPStan thinks the excluded class is executing on those properties but without the properties.

There are 4 Reader classes and two have the "Startoffset" and "fixedlength"

Technically, the issue being reported goes against standard OOP for traits. I'm refactoring it so it's not an issue, but it's still something phpstan should look at.