Writes the given data as one gzip member.
        
        The data can be a string, an iterator that gives strings or a file-like object.
190296
def write_member(self, data):
        
        if isinstance(data, basestring):
            self.write(data)
        else:
            for text in data:
                self.write(text)
        self.close_member()
242845
@Override
	public void writeBytes(String s)
    {
    	int len = s.length();
    	ensureCapacity(size+len);
    	for (int i = 0 ; i < len ; i++)
    	    buf[pos++] = (byte)s.charAt(i);
    }
    
	/* (non-Javadoc)
	 * @see java.io.DataOutput#writeChars(java.lang.String)
	 */
	@Override
	public void writeChars(String s)
	{
		int len = s.length();
		ensureCapacity(size+len*2);
        for (int i = 0 ; i < len ; i++) {
            int v = s.charAt(i);
            buf[pos++] = (byte)((v >>> 8) & 0xFF); 
            buf[pos++] = (byte)((v >>> 0) & 0xFF); 
        }
	}
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#write(byte[], int, int)
     */
    @Override
	public void write(byte[] data,int offset,int len)
    {
        int newCount = size+len; 
        ensureCapacity(newCount);
        System.arraycopy(data, offset, buf, size, len);
        size = newCount;
    }
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#writeByte(int)
     */
    @Override
	public void writeByte(int b)
    {
        ensureCapacity(size+1);
        buf[size++] = (byte)b;
    }
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#writeBoolean(boolean)
     */
    @Override
	public void writeBoolean(boolean v)
    {
        write(v ? 1 : 0);
    }
    
    /**
     * Read a byte value at an arbitrary position in the buffer
     * @param position the target position
     */
    public byte readByte(int position)
    {
    	return buf[position];
    }
    
    /**
     * Write a byte value at an arbitrary position in the buffer
     * @param v the byte value
     * @param position the target position
     */
    public void writeByte(byte v,int position)
    {
    	buf[position] = v;
    }
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#writeShort(int)
     */
    @Override
	public void writeShort(int v)
    {
        ensureCapacity(size + 2);
        buf[size++] = (byte)((v >>>  8) & 0xFF);
        buf[size++] = (byte)((v >>>  0) & 0xFF);
    }
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#writeInt(int)
     */
    @Override
	public void writeInt(int v)
    {
        ensureCapacity(size + 4);
        buf[size++] = (byte)((v >>> 24) & 0xFF);
        buf[size++] = (byte)((v >>> 16) & 0xFF);
        buf[size++] = (byte)((v >>>  8) & 0xFF);
        buf[size++] = (byte)((v >>>  0) & 0xFF);
    }
    
    /**
     * Write a int value at an arbitrary position in the stream
     * @param v the int value
     * @param pos the target position
     */
    public void writeInt(int v,int pos)
    {
        buf[pos++] = (byte)((v >>> 24) & 0xFF);
        buf[pos++] = (byte)((v >>> 16) & 0xFF);
        buf[pos++] = (byte)((v >>>  8) & 0xFF);
        buf[pos]   = (byte)((v >>>  0) & 0xFF);
    }
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#writeLong(long)
     */
    @Override
	public void writeLong(long v)
    {
        ensureCapacity(size + 8);
        buf[size++] = (byte)(v >>> 56);
        buf[size++] = (byte)(v >>> 48);
        buf[size++] = (byte)(v >>> 40);
        buf[size++] = (byte)(v >>> 32);
        buf[size++] = (byte)(v >>> 24);
        buf[size++] = (byte)(v >>> 16);
        buf[size++] = (byte)(v >>>  8);
        buf[size++] = (byte)(v >>>  0);
    }
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#writeFloat(float)
     */
    @Override
	public void writeFloat(float v)
    {
        writeInt(Float.floatToIntBits(v));
    }
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#writeDouble(double)
     */
    @Override
	public void writeDouble(double v)
    {
        writeLong(Double.doubleToLongBits(v));
    }
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#writeChar(int)
     */
    @Override
	public void writeChar(int v)
    {
        ensureCapacity(size + 2);
        buf[size++] = (byte)((v >>>  8) & 0xFF);
        buf[size++] = (byte)((v >>>  0) & 0xFF);
    }
    
    /*
     * (non-Javadoc)
     * @see java.io.DataOutput#writeUTF(java.lang.String)
     */
    @Override
	public void writeUTF(String str)
    {
        int strlen = str.length();
        if (strlen < 255)
            writeUTF(str,UTF_TYPE_1);
        else
        if (strlen < 65535)
            writeUTF(str,UTF_TYPE_2);
        else
            writeUTF(str,UTF_TYPE_4);
    }
    
    private void writeUTF( String str , byte type )
    {       
        // We need at least type + strlen bytes (1 byte/char) + 1
        int strlen = str.length();
        int rawlen = size+type+strlen+1;
        ensureCapacity(rawlen);
        
        // Write UTF type prefix
        buf[size++] = type;
        
        // Write the string length
        switch (type)
        {
            case UTF_TYPE_1 :
                buf[size++] = (byte)((strlen >>>  0) & 0xFF);
                break;
            case UTF_TYPE_2 :
                buf[size++] = (byte)((strlen >>>  8) & 0xFF);
                buf[size++] = (byte)((strlen >>>  0) & 0xFF);
                break;
            case UTF_TYPE_4 :
                buf[size++] = (byte)((strlen >>> 24) & 0xFF);
                buf[size++] = (byte)((strlen >>> 16) & 0xFF);
                buf[size++] = (byte)((strlen >>>  8) & 0xFF);
                buf[size++] = (byte)((strlen >>>  0) & 0xFF);
                break;
            default:
            	throw new IllegalArgumentException("Invalid UTF type : "+type);   
        }

        // Write the string
        int c,i = 0;
        for (i = 0 ; i < strlen ; i++)
        {
            c = str.charAt(i);
            if (!((c >= 0x0001) && (c <= 0x007F)))
                break;
            buf[size++] = (byte)c;
        }
        // Are we done ?
        if (i == strlen)
            return;

        // Fallback to full encoding mode
        for ( ; i < strlen ; i++)
        {
            c = str.charAt(i);

            if ((c >= 0x0001) && (c <= 0x007F))
            {
                // One byte
                buf[size++] = (byte)c;
            }
            else if (c > 0x07FF)
            {
                rawlen += 3;
                ensureCapacity(rawlen);
                
                buf[size++] = (byte)(0xE0 | ((c >> 12) & 0x0F));
                buf[size++] = (byte)(0x80 | ((c >> 6) & 0x3F));
                buf[size++] = (byte)(0x80 | ((c >> 0) & 0x3F));
            }
            else
            {
                rawlen += 2;
                ensureCapacity(rawlen);
                
                buf[size++] = (byte)(0xC0 | ((c >> 6) & 0x1F));
                buf[size++] = (byte)(0x80 | ((c >> 0) & 0x3F));
            }
        }
    }
722140
def write(self, i, value):
        
        # Current byte position - (n * data_size)
        offset = i * self.__strct.size

        # Set file pointer to -(#data)
        self.__file.seek(offset)

        # Pack value
        data = self.pack(value)

        # Write packed value
        self.__file.write(data)
989903
def bytes2zip(bytes):
    
    if hasattr(bytes, "read"):
        buff = TemporaryFile()
        archive = gzip.GzipFile(fileobj=buff, mode='w')
        for b in bytes:
            archive.write(b)
        archive.close()
        buff.seek(0)
        from pyLibrary.env.big_data import FileString, safe_size
        return FileString(buff)

    buff = BytesIO()
    archive = gzip.GzipFile(fileobj=buff, mode='w')
    archive.write(bytes)
    archive.close()
    return buff.getvalue()
41949
public static void writeCompressedStringArray(DataOutput out, String[] s) throws IOException {
        if (s == null) {
            out.writeInt(-1);
            return;
        }
        out.writeInt(s.length);
        for (int i = 0; i < s.length; i++) {
            writeCompressedString(out, s[i]);
        }
    }
569392
def _write_file(self, filename, data):
        

        if self.__compression:
            f = gzip.GzipFile(filename, "wb")
        else:
            f = open(filename, "wb")
        pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
        f.close()
408601
private static void writeString(String str, DataOutput writer) throws IOException {
		if (str == null) {
			writer.writeInt(0);
		} else {
			int blocks = str.length() >> 15;
			writer.writeInt(blocks+1);
			int end = 0;
			for (int i=0; i<blocks; i++) {
				int start = end;
				end = (i+1)<<15;
				writer.writeUTF(str.substring(start, end));
			}
			writer.writeUTF(str.substring(end));
		}
	}
1133590
function zip(data, options) {
		var flags = 0,
			level,
			crc, out = [];

		if (!options) {
			options = {};
		}
		level = options.level || DEFAULT_LEVEL;

		if (typeof data === 'string') {
			data = Array.prototype.map.call(data, function (char) {
				return char.charCodeAt(0);
			});
		}

		// magic number marking this file as GZIP
		putByte(ID1, out);
		putByte(ID2, out);

		putByte(compressionMethods['deflate'], out);

		if (options.name) {
			flags |= possibleFlags['FNAME'];
		}

		putByte(flags, out);
		putLong(options.timestamp || parseInt(Date.now() / 1000, 10), out);

		// put deflate args (extra flags)
		if (level === 1) {
			// fastest algorithm
			putByte(4, out);
		} else if (level === 9) {
			// maximum compression (fastest algorithm)
			putByte(2, out);
		} else {
			putByte(0, out);
		}

		// OS identifier
		putByte(osMap[os], out);

		if (options.name) {
			// ignore the directory part
			putString(options.name.substring(options.name.lastIndexOf('/') + 1), out);

			// terminating null
			putByte(0, out);
		}

		deflate.deflate(data, level).forEach(function (byte) {
			putByte(byte, out);
		});

		putLong(parseInt(crc32(data), 16), out);
		putLong(data.length, out);

		return out;
	}
407741
def decompress(data):
    
    with GzipFile(fileobj=io.BytesIO(data)) as f:
        return f.read()
1358851
@SuppressWarnings("PMD.AssignmentInOperand")
  static byte[] gunzip(byte[] data) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length * 10);
    try (InputStream in = new GZIPInputStream(new ByteArrayInputStream(data))) {
      byte[] buffer = new byte[4096];
      int length;
      while ((length = in.read(buffer)) > 0) {
        baos.write(buffer, 0, length);
      }
    }
    return baos.toByteArray();
  }
1140799
def __write(self, s):
        
        self.buf += s
        while len(self.buf) > self.bufsize:
            self.fileobj.write(self.buf[:self.bufsize])
            self.buf = self.buf[self.bufsize:]
154683
def writeString(self, s):
        
        s = self.context.getBytesForString(s)

        self.writeBytes(s)
416321
public final void write(byte[] data) {
    if (sendBinary) {
      int prev = 0;
      for (int i = 0;i < data.length;i++) {
        if (data[i] == -1) {
          rawWrite(data, prev, i - prev);
          send(new byte[]{-1, -1});
          prev = i + 1;
        }
      }
      rawWrite(data, prev, data.length - prev);
    } else {
      for (int i = 0;i < data.length;i++) {
        data[i] = (byte)(data[i] & 0x7F);
      }
      send(data);
    }
  }
909915
void addGzippedBytes(ReadableBuffer buffer) {
    checkState(!closed, "GzipInflatingBuffer is closed");
    gzippedData.addBuffer(buffer);
    isStalled = false;
  }
1108939
static byte[] gzip(byte[] data, int level) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length);
    try (GzipLevelOutputStream out = new GzipLevelOutputStream(baos)) {
      out.setLevel(level);
      out.write(data);
    }
    return baos.toByteArray();
  }
951645
def write(self, data):
        
        if self.padded:
            # flush out any remaining bits first
            if len(self._bits) > 0:
                self._flush_bits_to_stream()
            self._stream.write(data)
        else:
            # nothing to do here
            if len(data) == 0:
                return

            bits = bytes_to_bits(data)
            self.write_bits(bits)
145503
def write_blockdata(self, x, z, data, compression=COMPRESSION_ZLIB):
        
        if compression == COMPRESSION_GZIP:
            # Python 3.1 and earlier do not yet support `data = gzip.compress(data)`.
            compressed_file = BytesIO()
            f = gzip.GzipFile(fileobj=compressed_file)
            f.write(data)
            f.close()
            compressed_file.seek(0)
            data = compressed_file.read()
            del compressed_file
        elif compression == COMPRESSION_ZLIB:
            data = zlib.compress(data) # use zlib compression, rather than Gzip
        elif compression != COMPRESSION_NONE:
            raise ValueError("Unknown compression type %d" % compression)
        length = len(data)

        # 5 extra bytes are required for the chunk block header
        nsectors = self._bytes_to_sector(length + 5)

        if nsectors >= 256:
            raise ChunkDataError("Chunk is too large (%d sectors exceeds 255 maximum)" % (nsectors))

        # Ensure file has a header
        if self.size < 2*SECTOR_LENGTH:
            self._init_file()

        # search for a place where to write the chunk:
        current = self.metadata[x, z]
        free_sectors = self._locate_free_sectors(ignore_chunk=current)
        sector = self._find_free_location(free_sectors, nsectors, preferred=current.blockstart)

        # If file is smaller than sector*SECTOR_LENGTH (it was truncated), pad it with zeroes.
        if self.size < sector*SECTOR_LENGTH:
            # jump to end of file
            self.file.seek(0, SEEK_END)
            self.file.write((sector*SECTOR_LENGTH - self.size) * b"\x00")
            assert self.file.tell() == sector*SECTOR_LENGTH

        # write out chunk to region
        self.file.seek(sector*SECTOR_LENGTH)
        self.file.write(pack(">I", length + 1)) #length field
        self.file.write(pack(">B", compression)) #compression field
        self.file.write(data) #compressed data

        # Write zeros up to the end of the chunk
        remaining_length = SECTOR_LENGTH * nsectors - length - 5
        self.file.write(remaining_length * b"\x00")

        #seek to header record and write offset and length records
        self.file.seek(4 * (x + 32*z))
        self.file.write(pack(">IB", sector, nsectors)[1:])

        #write timestamp
        self.file.seek(SECTOR_LENGTH + 4 * (x + 32*z))
        timestamp = int(time.time())
        self.file.write(pack(">I", timestamp))

        # Update free_sectors with newly written block
        # This is required for calculating file truncation and zeroing freed blocks.
        free_sectors.extend((sector + nsectors - len(free_sectors)) * [True])
        for s in range(sector, sector + nsectors):
            free_sectors[s] = False
        
        # Check if file should be truncated:
        truncate_count = list(reversed(free_sectors)).index(False)
        if truncate_count > 0:
            self.size = SECTOR_LENGTH * (len(free_sectors) - truncate_count)
            self.file.truncate(self.size)
            free_sectors = free_sectors[:-truncate_count]
        
        # Calculate freed sectors
        for s in range(current.blockstart, min(current.blockstart + current.blocklength, len(free_sectors))):
            if free_sectors[s]:
                # zero sector s
                self.file.seek(SECTOR_LENGTH*s)
                self.file.write(SECTOR_LENGTH*b'\x00')
        
        # update file size and header information
        self.size = max((sector + nsectors)*SECTOR_LENGTH, self.size)
        assert self.get_size() == self.size
        current.blockstart = sector
        current.blocklength = nsectors
        current.status = STATUS_CHUNK_OK
        current.timestamp = timestamp
        current.length = length + 1
        current.compression = COMPRESSION_ZLIB