Hello all, I've attached a proposed patch to improve our handling of BOMs. Here are a few notable aspects: * All kinds of streams are supported in a uniform way: files, pipes, sockets, terminals, etc. * As specified in Unicode 6.2, BOMs are only handled specially at the start of a stream, and only if the encoding is set to "UTF-16" or "UTF-32". BOMs are *not* handled specially if the encoding is set to "UTF-16LE", etc. * This code never tries to read a BOM until the user has asked to read. If the user writes before reading, it chooses big-endian and writes a BOM if appropriate (if the encoding is set to "UTF-16" or "UTF-32"). * The encodings "UTF-16" and "UTF-32" are *never* passed to iconv, because BOM handling varies between iconv implementations. Creation of the iconv descriptors is always postponed until the first read or write, at which point a decision is made about the endianness, and then "UTF-16BE", "UTF-16LE", "UTF-32BE", or "UTF-32LE" is passed to iconv. * If 'rw_random' is zero, then the input and output streams are considered independent: the first read will consume a BOM if appropriate, *and* the first write will produce a BOM if appropriate. * If 'rw_random' is non-zero, then the input and output streams are considered linked: if the user reads first, then a BOM will be consumed if appropriate, but later writes will *not* produce a BOM. Similarly, if the user writes first, then later reads will *not* consume a BOM. * If 'set-port-encoding!' is called in the middle of a stream, it treats it as a new logical "start of stream", i.e. if the encoding is set to "UTF-16" or "UTF-32" then a BOM will be consumed the next time you read and/or produced the next time you write. * Seeks to the beginning of the file set the "start of stream" flags. Seeks anywhere else clear the "start of stream" flags. Okay, here's the patch. Comments and suggestions solicited. Mark