internal void WriteMeta(DataStream[] streams, BitAccess bits) {
      PdbFileHeader head = new PdbFileHeader(pageSize);

      WriteDirectory(streams,
                     out head.directoryRoot,
                     out head.directorySize,
                     bits);
      WriteFreeMap();

      head.freePageMap = 2;
      head.pagesUsed = usedBytes / pageSize;

      writer.Seek(0, SeekOrigin.Begin);
      head.Write(writer, bits);
    }
    private void WriteDirectory(DataStream[] streams,
                                out int directoryRoot,
                                out int directorySize,
                                BitAccess bits) {
      DataStream directory = new DataStream();

      int pages = 0;
      for (int s = 0; s < streams.Length; s++) {
        if (streams[s].Length > 0) {
          pages += streams[s].Pages;
        }
      }

      int use = 4 * (1 + streams.Length + pages);
      bits.MinCapacity(use);
      bits.WriteInt32(streams.Length);
      for (int s = 0; s < streams.Length; s++) {
        bits.WriteInt32(streams[s].Length);
      }
      for (int s = 0; s < streams.Length; s++) {
        if (streams[s].Length > 0) {
          bits.WriteInt32(streams[s].pages);
        }
      }
      directory.Write(this, bits.Buffer, use);
      directorySize = directory.Length;

      use = 4 * directory.Pages;
      bits.MinCapacity(use);
      bits.WriteInt32(directory.pages);

      DataStream ddir = new DataStream();
      ddir.Write(this, bits.Buffer, use);

      directoryRoot = ddir.pages[0];
    }