From: Nicolas C. <war...@fr...> - 2004-04-09 13:16:13
|
> > Could you explain how really_input cannot be used on stdin ? Maybe I > > misunderstood the differences with input, but the documentation doesn't say > > anything about really_input not working on stdin. > > Apologies - I sent that by accident before I was ready, so it wasn't > phrased very well. Of course really_input works on stdin, I was > thinking of in_channel_length, and IO does wrap that appropriately. > > However, the specific case that was giving me problems was using IO as a > layer for accessing a stream compressed with zlib. The stream might be > stdin, so I can't count on knowing how long it is, but for efficiency I > want to read it in blocks rather than one byte at a time. In C I'd use > fread(), in ocaml normally I'd use Pervasives.input. IO currently > provides no equivalent. Sure, it can be done char by char with IO.read, > but I'm pretty sure that's going to wind up much less efficient than a > hypothetical function which called Pervasives.input, String.sub, or > whatever as appropriate. Sure. Actually IO does not work maybe well with buffered streams : the specification is that when you're reading n "elements" (characters or any) from an input, the result will be exactly the n elements you needed. Not more, and not less. This might actually be questionable : if you have spare time, could you suggest what parts of IO module should be modified in order to support buffered streams ? If it's only replacing Pervasives.really_input by input (and thus change the specification) I think it's worth doing. > I note that this seems to be inconvenient for you, too, going by the > zlib code you just posted. ;) Since I want to be able to use data from > stdin, and I want to be able to handle streams larger than > Sys.max_string_length, I can't use your version... This code is still experimental, and will surely be evolve into something more usable. As for everything else, any suggestion/code contribution will be apprecied. Regards, Nicolas Cannasse |