Move memstream to common utils.