Extract writing boilerplate into wstream.c module