modified binmode rather than doing the lineendings manually