package flate

import (
	
	

	
)

func () matchfinder.Encoder {
	return &gzipEncoder{
		f: NewEncoder(),
	}
}

type gzipEncoder struct {
	f           matchfinder.Encoder
	length      uint32
	crc         uint32
	wroteHeader bool
}

func ( *gzipEncoder) () {
	.f.Reset()
	.length = 0
	.crc = 0
	.wroteHeader = false
}

func ( []byte,  uint32) []byte {
	return append(,
		byte(),
		byte(>>8),
		byte(>>16),
		byte(>>24),
	)
}

func ( *gzipEncoder) ( []byte,  []byte,  []matchfinder.Match,  bool) []byte {
	if !.wroteHeader {
		 = append(,
			0x1f, 0x8b, // magic number
			8, // CM = flate
			0, // FLG
		)
		 = appendUint32(, uint32(time.Now().Unix()))
		 = append(,
			0,   // XFL
			255, // OS (unspecified)
		)
		.wroteHeader = true
	}

	 = .f.Encode(, , , )

	.length += uint32(len())
	.crc = crc32.Update(.crc, crc32.IEEETable, )

	if  {
		 = appendUint32(, .crc)
		 = appendUint32(, .length)
	}

	return 
}