fCraft.Map.GetCompressedCopy C# (CSharp) Method

GetCompressedCopy() public method

Writes a copy of the current map to a given stream, compressed with GZipStream.
public GetCompressedCopy ( [ stream, bool prependBlockCount ) : void
stream [ Stream to write the compressed data to.
prependBlockCount bool If true, prepends block data with signed, 32bit, big-endian block count.
return void
        public void GetCompressedCopy( [NotNull] Stream stream, bool prependBlockCount )
        {
            if ( stream == null )
                throw new ArgumentNullException( "stream" );
            using ( GZipStream compressor = new GZipStream( stream, CompressionMode.Compress ) ) {
                if ( prependBlockCount ) {
                    // convert block count to big-endian
                    int convertedBlockCount = IPAddress.HostToNetworkOrder( Blocks.Length );
                    // write block count to gzip stream
                    compressor.Write( BitConverter.GetBytes( convertedBlockCount ), 0, 4 );
                }
                compressor.Write( Blocks, 0, Blocks.Length );
            }
        }

Usage Example

Example #1
0
 byte[] GetCompressedBlocks(Map map) {
 	bool customBlocks = Supports(CpeExtension.CustomBlocks);
 	if (customBlocks && Supports(CpeExtension.BlockDefinitions))
 		return map.GetCompressedCopy(map.Blocks);
 	
 	byte[] blocks = customBlocks ? 
 		map.GetCPEFallbackMap() : map.GetFallbackMap();
 	return Map.MakeCompressedMap(blocks);
 }