Skip to content

Commit 72b8bf3

Browse files
committed
Store YBlob as bytes, not base64-encoded string
1 parent 947c46e commit 72b8bf3

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

jupyter_ydoc/yblob.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4-
import base64
54
from functools import partial
6-
from typing import Any, Callable, Optional, Union
5+
from typing import Any, Callable, Optional
76

87
from pycrdt import Doc, Map
98

@@ -13,10 +12,7 @@
1312
class YBlob(YBaseDoc):
1413
"""
1514
Extends :class:`YBaseDoc`, and represents a blob document.
16-
It is currently encoded as base64 because of:
17-
https://github.com/y-crdt/ypy/issues/108#issuecomment-1377055465
18-
The Y document can be set from bytes or from str, in which case it is assumed to be encoded as
19-
base64.
15+
The Y document is set from bytes.
2016
2117
Schema:
2218
@@ -46,7 +42,7 @@ def version(self) -> str:
4642
:return: Document's version.
4743
:rtype: str
4844
"""
49-
return "1.0.0"
45+
return "2.0.0"
5046

5147
def get(self) -> bytes:
5248
"""
@@ -55,18 +51,16 @@ def get(self) -> bytes:
5551
:return: Document's content.
5652
:rtype: bytes
5753
"""
58-
return base64.b64decode(self._ysource.get("base64", "").encode())
54+
return self._ysource.get("bytes", b"")
5955

60-
def set(self, value: Union[bytes, str]) -> None:
56+
def set(self, value: bytes) -> None:
6157
"""
6258
Sets the content of the document.
6359
6460
:param value: The content of the document.
65-
:type value: Union[bytes, str]
61+
:type value: bytes
6662
"""
67-
if isinstance(value, bytes):
68-
value = base64.b64encode(value).decode()
69-
self._ysource["base64"] = value
63+
self._ysource["bytes"] = value
7064

7165
def observe(self, callback: Callable[[str, Any], None]) -> None:
7266
"""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ requires-python = ">=3.7"
1313
keywords = ["jupyter", "ypy"]
1414
dependencies = [
1515
"importlib_metadata >=3.6; python_version<'3.10'",
16-
"pycrdt >=0.8.1,<0.9.0",
16+
"pycrdt >=0.8.3,<0.9.0",
1717
]
1818

1919
[[project.authors]]

0 commit comments

Comments
 (0)