extended to work with file object or fd's