1
1
# Copyright (c) Jupyter Development Team.
2
2
# Distributed under the terms of the Modified BSD License.
3
3
4
- import base64
5
4
from functools import partial
6
- from typing import Any , Callable , Optional , Union
5
+ from typing import Any , Callable , Optional
7
6
8
7
from pycrdt import Doc , Map
9
8
13
12
class YBlob (YBaseDoc ):
14
13
"""
15
14
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.
20
16
21
17
Schema:
22
18
@@ -46,7 +42,7 @@ def version(self) -> str:
46
42
:return: Document's version.
47
43
:rtype: str
48
44
"""
49
- return "1 .0.0"
45
+ return "2 .0.0"
50
46
51
47
def get (self ) -> bytes :
52
48
"""
@@ -55,18 +51,16 @@ def get(self) -> bytes:
55
51
:return: Document's content.
56
52
:rtype: bytes
57
53
"""
58
- return base64 . b64decode ( self ._ysource .get ("base64 " , "" ). encode () )
54
+ return self ._ysource .get ("bytes " , b"" )
59
55
60
- def set (self , value : Union [ bytes , str ] ) -> None :
56
+ def set (self , value : bytes ) -> None :
61
57
"""
62
58
Sets the content of the document.
63
59
64
60
:param value: The content of the document.
65
- :type value: Union[ bytes, str]
61
+ :type value: bytes
66
62
"""
67
- if isinstance (value , bytes ):
68
- value = base64 .b64encode (value ).decode ()
69
- self ._ysource ["base64" ] = value
63
+ self ._ysource ["bytes" ] = value
70
64
71
65
def observe (self , callback : Callable [[str , Any ], None ]) -> None :
72
66
"""
0 commit comments