Try using a Buffer.concat instead of manually performing copies