Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix local file reading for mo.audio (#1020)

Akshay Agrawald167da0bdd87
diff --git a/marimo/_plugins/core/media.py b/marimo/_plugins/core/media.py
index 1ecddaf06b..40448e9a43 100644
--- a/marimo/_plugins/core/media.py
+++ b/marimo/_plugins/core/media.py
@@ -39,10 +39,10 @@ def io_to_data_url(
if src is None:
return None
- if isinstance(src, io.BytesIO):
- # clone before reading, so we don't consume the stream
- src = io.BytesIO(src.getvalue())
+ if isinstance(src, (io.BufferedIOBase, io.RawIOBase)):
+ pos = src.tell()
base64_string = base64.b64encode(src.read()).decode("utf-8")
+ src.seek(pos)
file_type = guess_mime_type(src) or fallback_mime_type
return f"data:{file_type};base64,{base64_string}"