Why should it work different? Text files are just regular files where the bytes only use a specific subset of the possible values they could have.
If you do have some knowledge about the data you are encoding, you can be a little bit smarter about it: e.g. for the text section of an executable, you might work on individual instructions instead of bytes, maybe use common, prepared Huffman Trees, so you don't have to encode the tree itself.
On a side note: IIRC the Intel Management Engine does that using a proprietary Huffman Tree, backed into the hardware itself, as an obfuscation technique[1].
To circle back to your question: PNG simply feeds the pixel data into the zlib deflate() function as-is.
[1] https://en.wikipedia.org/wiki/Intel_Management_Engine#Design
And it actually does often work differently for PNG! PNG has a handful of preprocessing options for the pixels. So in filter mode 2, for example, deflate is encoding the difference between each pixel and the pixel above it. More or less.
I think this is true even when using 16 bits per sample, but i'm not sure.
From what i remember, in gzip, Huffman coding is applied to the offsets of repeated blocks, which are not single bytes.
Some encoders just use a precomputed Huffman table, but you can make an optimized one as discussed here[3].
Huffman is not the most optimal compression that can be used, for example Dropbox's Lepton[4] saves an additional 20% by replacing the Huffman stage with something better.
However, since it's a lossless stage this can be done transparently, which is nice.
[1]: http://www.robertstocker.co.uk/jpeg/jpeg_new_11.htm
[2]: https://www.impulseadventure.com/photo/jpeg-huffman-coding.h...
[3]: https://www.impulseadventure.com/photo/optimized-jpeg.html
[4]: https://dropbox.tech/infrastructure/lepton-image-compression...
Anything to save a few bits...
It is generally used as the final stage of some other compression algorithm, and operates on symbols generated by that algorithm. Often, this is some variation on LZ77, and the symbols are something like "bytes 0-255" in addition to various symbols that denote a match in previous data of some length and at some offset.