Impemented compression and rewored how stream is opened/reopened