I would say that the current patch looks correct enough, in that it would still get the correct lengths when a memoryview() object is passed in. The zlib module’s crc32() function and compress() method already seem to support arbitrary bytes-like objects.
But to make GzipFile.write() also accept arbitrary bytes-like objects, you probably only need to change the code calculating the length to something like:
with memoryview(data) as view:
length = view.nbytes
# Go on to call compress(data) and crc32(data)