@@ -27,24 +27,30 @@ def new(name, pipe_mode=False):
27
27
self .name = name
28
28
self .pipe_mode = pipe_mode
29
29
self .loaded_bytes = open (name , 'rb' ).read ()
30
- self .memory = memoryview (loaded_bytes )
30
+ self .memory = memoryview (self . loaded_bytes )
31
31
self .length = len (self .loaded_bytes )
32
32
self .read_point = 0
33
33
34
34
return self .build ()
35
35
36
36
def read_cb (self , buf ):
37
- #print('read: {0} bytes ...'.format(len(buf)))
37
+ # print('read: {0} bytes ...'.format(len(buf)))
38
38
p = self .read_point
39
39
bytes_available = self .length - p
40
40
bytes_to_copy = min (bytes_available , len (buf ))
41
41
buf [:bytes_to_copy ] = self .memory [p :p + bytes_to_copy ]
42
42
self .read_point += bytes_to_copy
43
+ # print(' copied from position {0}'.format(p))
43
44
44
45
return bytes_to_copy
45
46
46
47
def seek_cb (self , offset , whence ):
47
- #print('seek: offset = {0}, whence = {1} ...'.format(offset, whence))
48
+ # print('seek: offset = {0}, whence = {1} ...'.format(offset, whence))
49
+
50
+ if self .pipe_mode :
51
+ # print(' -1 (pipe mode)')
52
+ return - 1
53
+
48
54
if whence == 0 :
49
55
# SEEK_SET
50
56
new_read_point = offset
@@ -58,12 +64,9 @@ def seek_cb(self, offset, whence):
58
64
raise Exception ('bad whence {0}' .format (whence ))
59
65
60
66
self .read_point = max (0 , min (self .length , new_read_point ))
61
- #print(' new read_point = {0}'.format(self.read_point))
67
+ # print(' new read_point = {0}'.format(self.read_point))
62
68
63
- if self .pipe_mode :
64
- return - 1
65
- else :
66
- return self .read_point
69
+ return self .read_point
67
70
68
71
69
72
class Mystreamo (pyvips .Streamou ):
@@ -90,14 +93,14 @@ def new(name):
90
93
return self .build ()
91
94
92
95
def write_cb (self , buf ):
93
- #print('write: {0} bytes ...'.format(len(buf)))
94
-
96
+ # print('write: {0} bytes ...'.format(len(buf)))
97
+ # py2 write does not return number of bytes written
95
98
self .f .write (buf )
96
99
97
100
return len (buf )
98
101
99
102
def finish_cb (self ):
100
- #print('finish: ...')
103
+ # print('finish: ...')
101
104
self .f .close ()
102
105
103
106
@@ -128,8 +131,8 @@ def test_streamu(self):
128
131
streamou = Mystreamo .new (filename )
129
132
image .write_to_stream (streamou , '.png' )
130
133
131
- image = pyvips .Image .new_from_file (JPEG_FILE )
132
- image2 = pyvips .Image .new_from_file (filename )
134
+ image = pyvips .Image .new_from_file (JPEG_FILE , access = 'sequential' )
135
+ image2 = pyvips .Image .new_from_file (filename , access = 'sequential' )
133
136
134
137
assert abs (image - image2 ).abs ().max () < 10
135
138
@@ -142,7 +145,7 @@ def test_streamu_pipe(self):
142
145
streamou = Mystreamo .new (filename )
143
146
image .write_to_stream (streamou , '.png' )
144
147
145
- image = pyvips .Image .new_from_file (JPEG_FILE )
146
- image2 = pyvips .Image .new_from_file (filename )
148
+ image = pyvips .Image .new_from_file (JPEG_FILE , access = 'sequential' )
149
+ image2 = pyvips .Image .new_from_file (filename , access = 'sequential' )
147
150
148
151
assert abs (image - image2 ).abs ().max () < 10
0 commit comments