# Buggy code
def read(self, n=-1):
    chunk = self.reader(n)
    if self.is_text_file is None:
        self.is_text_file = istextblock(chunk)

    if self.is_text_file:
        data = dos2unix(chunk)
    else:
        data = chunk
    self.md5.update(data)

    return chunk


# Traceback (AttributeError)
dvc add --to-remote -o datasets/my-dataset/ --file my-dataset.dvc afile.zip --verbose
2021-02-23 08:28:44,338 DEBUG: Check for update is enabled.
Adding...
2021-02-23 08:28:46,408 ERROR: unexpected error - 'HashedStreamReader' object has no attribute 'tell'
------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/main.py", line 50, in main
ret = cmd.run()
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/command/add.py", line 32, in run
jobs=self.args.jobs,
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/repo/__init__.py", line 49, in wrapper
return f(repo, *args, **kwargs)
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/repo/scm_context.py", line 14, in run
return method(repo, *args, **kw)
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/repo/add.py", line 131, in add
**kwargs,
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/repo/add.py", line 172, in _process_stages
command="add",
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/data_cloud.py", line 111, in transfer
return remote.transfer(from_fs, from_fs.path_info, jobs=jobs)
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/remote/base.py", line 520, in transfer
no_progress_bar=no_progress_bar,
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/objects/__init__.py", line 312, in transfer
tmp_info, hash_info = _transfer_file(odb, from_fs, from_info)
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/objects/__init__.py", line 254, in _transfer_file
desc=from_info.name,
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/fs/base.py", line 256, in upload_fobj
self._upload_fobj(wrapped, to_info)  # pylint: disable=no-member
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/fs/gs.py", line 203, in _upload_fobj
_upload_to_bucket(bucket, fobj, to_info)
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/fs/gs.py", line 38, in wrapper
return func(*args, chunk_size=chunk_size, **kwargs)
File "/usr/local/anaconda3/lib/python3.7/site-packages/dvc/fs/gs.py", line 50, in _upload_to_bucket
blob.upload_from_file(fobj)
File "/usr/local/anaconda3/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 1167, in upload_from_file
client, file_obj, content_type, size, num_retries, predefined_acl
File "/usr/local/anaconda3/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 1077, in _do_upload
client, stream, content_type, size, num_retries, predefined_acl
File "/usr/local/anaconda3/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 1020, in _do_resumable_upload
predefined_acl=predefined_acl,
File "/usr/local/anaconda3/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 969, in _initiate_resumable_upload
stream_final=False,
File "/usr/local/anaconda3/lib/python3.7/site-packages/google/resumable_media/requests/upload.py", line 402, in initiate
stream_final=stream_final,
File "/usr/local/anaconda3/lib/python3.7/site-packages/google/resumable_media/_upload.py", line 463, in _prepare_initiate_request
if stream.tell() != 0:
File "/usr/local/anaconda3/lib/python3.7/site-packages/tqdm/utils.py", line 88, in __getattr__
return getattr(self._wrapped, name)
AttributeError: 'HashedStreamReader' object has no attribute 'tell'
------------------------------------------------------------
2021-02-23 08:28:47,265 DEBUG: Version info for developers:
DVC version: 2.0.0a0+27c240
---------------------------------
Platform: Python 3.7.3 on Darwin-20.3.0-x86_64-i386-64bit
Supports: All remotes
Cache types: <https://error.dvc.org/no-dvc-cache>
Caches: local
Remotes: gs
Workspace directory: apfs on /dev/disk1s5s1
Repo: dvc, git

Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!
2021-02-23 08:28:47,267 DEBUG: Analytics is enabled.
2021-02-23 08:28:47,534 DEBUG: Trying to spawn '['daemon', '-q', 'analytics', '/var/folders/vx/n884kynx5ps8hksttp4mwl64010gl8/T/tmpeo2oe0g6']'
2021-02-23 08:28:47,536 DEBUG: Spawned '['daemon', '-q', 'analytics', '/var/folders/vx/n884kynx5ps8hksttp4mwl64010gl8/T/tmpeo2oe0g6']'

# Fixed code
def read(self, n=-1):
    chunk = self._reader(n)
    if self.is_text_file is None:
        self.is_text_file = istextblock(chunk)

    if self.is_text_file:
        data = dos2unix(chunk)
    else:
        data = chunk
    self.md5.update(data)

    return chunk