GitHub issue #5724: Error after shuffling streaming IterableDatasets with downloaded dataset
State: closed | Created: 2023-04-09T16:58:44Z

### Describe the bug

I downloaded the C4 dataset, and used streaming IterableDatasets to read it. Everything went normal until I used `dataset = dataset.shuffle(seed=42, buffer_size=10_000)` to shuffle the dataset. Shuffled dataset will throw the following error when it is used by `next(iter(dataset))`:
```
File "/data/miniconda3/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 937, in __iter__                                     
    for key, example in ex_iterable:                              
  File "/data/miniconda3/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 627, in __iter__                                     
    for x in self.ex_iterable:                                               
  File "/data/miniconda3/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 138, in __iter__                                     
    yield from self.generate_examples_fn(**kwargs_with_shuffled_shards)
  File "/data/miniconda3/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 763, in wrapper                                      
    for key, table in generate_tables_fn(**kwargs):                            
  File "/data/miniconda3/lib/python3.9/site-packages/datasets/packaged_modules/json/json.py", line 101, in _generate_tables                   
    batch = f.read(self.config.chunksize)   
  File "/data/miniconda3/lib/python3.9/site-packages/datasets/download/streaming_download_manager.py", line 372, in read_with_retries         
    out = read(*args, **kwargs)
  File "/data/miniconda3/lib/python3.9/gzip.py", line 300, in read
    return self._buffer.read(size)
  File "/data/miniconda3/lib/python3.9/_compression.py", line 68, in readinto                                                                 
    data = self.read(len(byte_view))       
  File "/data/miniconda3/lib/python3.9/gzip.py", line 487, in read
    if not self._read_gzip_header():                                  
  File "/data/miniconda3/lib/python3.9/gzip.py", line 435, in _read_gzip_header                                                               
    raise BadGzipFile('Not a gzipped file (%r)' % magic)
gzip.BadGzipFile: Not a gzipped file (b've')
```
I found that there is no problem to use the dataset in this way without shuffling. Also, use `dataset = datasets.load_dataset('c4', 'en', split='train', streaming=True)`, which will download the dataset on-the-fly instead of loading from the local file, will also not have problems even after shuffle.

### Steps to reproduce the bug

1. Download C4 dataset from https://huggingface.co/datasets/allenai/c4
2. 
```
import datasets
dataset = datasets.load_dataset('/path/to/your/data/dir', 'en', streaming=True, split='train')
dataset = dataset.shuffle(buffer_size=10_000, seed=42)
next(iter(dataset))
```

### Expected behavior

`next(iter(dataset))` should give me a sample from the dataset

### Environment info

- `datasets` version: 2.11.0
- Platform: Linux-5.4.32-1-tlinux4-0001-x86_64-with-glibc2.28
- Python version: 3.9.16
- Huggingface_hub version: 0.13.1
- PyArrow version: 11.0.0
- Pandas version: 1.5.3