python-filewrap 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
filewrap/__init__.py CHANGED
@@ -2,16 +2,17 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
- __version__ = (0, 3, 0)
5
+ __version__ = (0, 3, 1)
6
6
  __all__ = [
7
7
  "SupportsRead", "SupportsReadinto", "SupportsWrite", "SupportsSeek",
8
8
  "AsyncBufferedReader", "AsyncTextIOWrapper", "buffer_length", "to_string_buffer",
9
- "to_bytes_buffer", "bio_chunk_iter", "bio_chunk_async_iter", "bio_skip_iter",
10
- "bio_skip_async_iter", "bytes_iter", "bytes_async_iter", "bytes_iter_skip",
11
- "bytes_async_iter_skip", "bytes_iter_to_reader", "bytes_iter_to_async_reader",
12
- "bytes_to_chunk_iter", "bytes_to_chunk_async_iter", "bytes_ensure_part_iter",
13
- "bytes_ensure_part_async_iter", "progress_bytes_iter", "progress_bytes_async_iter",
14
- "copyfileobj", "copyfileobj_async", "bound_bytes_reader", "bound_async_bytes_reader",
9
+ "to_bytes_buffer", "to_bytes_view", "bio_chunk_iter", "bio_chunk_async_iter",
10
+ "bio_skip_iter", "bio_skip_async_iter", "bytes_iter", "bytes_async_iter",
11
+ "bytes_iter_skip", "bytes_async_iter_skip", "bytes_iter_to_reader",
12
+ "bytes_iter_to_async_reader", "bytes_to_chunk_iter", "bytes_to_chunk_async_iter",
13
+ "bytes_ensure_part_iter", "bytes_ensure_part_async_iter", "progress_bytes_iter",
14
+ "progress_bytes_async_iter", "copyfileobj", "copyfileobj_async", "bound_bytes_reader",
15
+ "bound_async_bytes_reader",
15
16
  ]
16
17
 
17
18
  from array import array
@@ -839,7 +840,21 @@ def to_string_buffer(s: str, /) -> array:
839
840
  def to_bytes_buffer(b: Buffer, /) -> bytes | bytearray | memoryview:
840
841
  if isinstance(b, (bytes, bytearray)):
841
842
  return b
842
- return memoryview(b).cast("B")
843
+ view = memoryview(b)
844
+ if view.format == "B":
845
+ return view
846
+ if view.c_contiguous:
847
+ return view.cast("B")
848
+ return view.tobytes()
849
+
850
+
851
+ def to_bytes_view(b: Buffer, /) -> memoryview:
852
+ view = memoryview(b)
853
+ if view.format == "B":
854
+ return view
855
+ if view.c_contiguous:
856
+ return view.cast("B")
857
+ return memoryview(view.tobytes())
843
858
 
844
859
 
845
860
  def bio_chunk_iter(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-filewrap
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Python file wrappers.
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -0,0 +1,6 @@
1
+ filewrap/__init__.py,sha256=uiw-wFsa545ZgkVDyrZNw0fDVRsbDdz1Xyc3hnmRhjc,61374
2
+ filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ python_filewrap-0.3.1.dist-info/METADATA,sha256=Zgsmzk5yW-5mFnEsc4Cjf8LlHoeaVPbB06BXb4VBCjk,1417
4
+ python_filewrap-0.3.1.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
5
+ python_filewrap-0.3.1.dist-info/licenses/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
6
+ python_filewrap-0.3.1.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- filewrap/__init__.py,sha256=39yU6QyabFchtrykF_4uiL4y4Ytm2MzeuCd7CCUuhH8,61018
2
- filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- python_filewrap-0.3.0.dist-info/METADATA,sha256=X36-8X7woDyEu1LJHgjuDSe99qPm2Suf0Ta7Itl3HIQ,1417
4
- python_filewrap-0.3.0.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
5
- python_filewrap-0.3.0.dist-info/licenses/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
6
- python_filewrap-0.3.0.dist-info/RECORD,,