Separate io helpers from _libs.lib
Avoids overlap with #19360 where possible.

Moved functions are cut/paste verbatim.

I'm open to a better name than io_helpers, just wanted to avoid overlap with the stdlib name "io".

Besides refactoring for its own sake, part of the goal is to get lib down the point where we can merge src/inference back into it; the split file makes it tough to track dependencies, and AFAICT it makes the move towards using cythonize easier.