Serialization using python failing because the buffer is empty.
Hi,

I'm probably holding this wrong, but I'm on the serialization branch of KSC at `4066d1e2d712` and used it generate python code to write a file but it doesn't look like i can serialize a file with Python 3.10 without first setting giving the file some contents.

I grabbed png.ksy off https://ide.kaitai.io/ and generated a Png.py.

I then do 
```
from kaitaistruct import KaitaiStream
from png import Png
data = Png.from_file('1x1.png')
data._read()
buffer = open('out.png', 'bw')
_io = KaitaiStream(buffer)
data._write(_io)
```

which throws 
```
File ~/projects/speedier/jupyter_env/lib/python3.10/site-packages/kaitaistruct.py:468, in KaitaiStream._ensure_bytes_left_to_write(self, n, pos)
    466 print("size:", full_size, "pos:", pos, "n:", n)
    467 if n > num_bytes_left:
--> 468     raise EOFError(
    469         "requested to write %d bytes, but only %d bytes left in the stream" %
    470         (n, num_bytes_left)
    471     )
EOFError: requested to write 4 bytes, but only 0 bytes left in the stream`
```

If I set the buffer size first it succeeds:

```
from kaitaistruct import KaitaiStream
from png import Png
data = Png.from_file('1x1.png')
data._read()
buffer = open('out.png', 'bw')
s = u'\0'*95
buffer.write(s.encode('utf-8'))
buffer.seek(0,0)
_io = KaitaiStream(buffer)
data._write(_io)
```

The [serialization guide](https://doc.kaitai.io/serialization.html) doesn't say I need to call other functions before calling `._write()`, but maybe I've skipped something?

I'm digging into skipping over the problem by modifying `kaitaistruct.py`, but was hoping I'm just missing something.