'Writes data from a stream'

def write_from_stream(self, dataset, stream):

    (fd, temp_name) = tempfile.mkstemp()
    while True:
        chunk = stream.read(1048576)
        if (not chunk):
            break
        os.write(fd, chunk)
    os.close(fd)
    fp = open(dataset.file_name, 'w')
    for line in open(temp_name, 'U'):
        line = (line.strip() + '\n')
        fp.write(line)
    fp.close()
