summaryrefslogtreecommitdiff
path: root/rsa/blocks.py
diff options
context:
space:
mode:
Diffstat (limited to 'rsa/blocks.py')
-rw-r--r--rsa/blocks.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/rsa/blocks.py b/rsa/blocks.py
index c38c1f2..0250566 100644
--- a/rsa/blocks.py
+++ b/rsa/blocks.py
@@ -132,3 +132,22 @@ def yield_varblocks(infile):
yield block
+def yield_fixedblocks(infile, blocksize):
+ '''Generator, yields each block of ``blocksize`` bytes in the input file.
+
+ :param infile: file to read and separate in blocks.
+ :returns: a generator that yields the contents of each block
+ '''
+
+ while True:
+ block = infile.read(blocksize)
+
+ read_bytes = len(block)
+ if read_bytes == 0:
+ break
+
+ yield block
+
+ if read_bytes < blocksize:
+ break
+