Extend deflate function to support custom window size