# Working with non-tabular files

### **Load a single file**

```python
import redivis
from io import TextIOWrapper
from PIL import Image

# See https://redivis.com/datasets/yz1s-d09009dbb/files for example data
table = redivis.table("demo.example_data_files:yz1s:v1_3.example_file_types:4c10")
text_file = table.file("pandas_core.py")
image_file = table.file("bogota.tiff"")

## Read file contents
str = text_file.read(as_text=True)
bytes = image_file.read()

## Open the file, as if it was on the filesystem
with file.open("rb") as f:
  f.read(100) # read 100 bytes

with file.open() as f:
  f.readline() # read first line
  
# Tools that integrate with fsspec can open Redivis URIs:
pystac.Catalog.from_file("redivis://table_ref/stac/catalog.json")
  
Image.open(table.file("bogota.tiff")) # PIL will automatically call open() on the file
  
## Download the file  
image_file.download("./path") # will be downloaded as ./path/bogota.tiff
text_file.download("./path/renamed.txt") # will be downloaded as ./path/renamed.txt
```

### Load all files in a table

```python
import redivis

table = redivis.table("Demo.example_data_files.example_file_types")

dir = redivis.table("table_ref").to_directory()
file = dir.get("path/to/file.txt") # Will return None if doesn't exist
dir.download("/download/path") # Download all files to the provided path
dir.mount("/download/path")
# dir.mount() behaves the same as dir.download() was called (all files appear on disk)
# However, this doesn't actually download the files until they're needed, 
#    and as such is much faster, particularly when all files may not need to be read.
```
