HI I trying to build a function that read IO a file and finds the position of a Marker
I would like to do it in cython with the C functions fopen and fgets
but I do not know how to convert the tring that I get in the fgets into a python string.
In the following example a file is read as python and with the c functions, when is
read as python I find the marker but when a read with the C function I can not find the marker.
Would like to ask how can be done so?
def _read_seq1 (self, filename, MARKER, n_frame, BLOCK_SIZE):
filename_byte_string = filename.encode("UTF-8")
cdef char* fname = filename_byte_string
cdef FILE* cfl
cfl = fopen(fname, "rb")
fl = open(filename, 'rb')
if cfl == NULL:
return -1, ""
cdef size_t _block_size = BLOCK_SIZE
string_val = "x" * (BLOCK_SIZE + 1)
cdef char* block = string_val
current = ""
frame_data = ""
ii_frame = 0
count = 0
current1 = ""
block1 = ""
while True:
if fgets(block, _block_size, cfl) == NULL: break
block1 = fl.read(BLOCK_SIZE)
current1 += block1
current += unicode(block, "ISO-8859-1").encode('utf8') ### How to do this part
markerpos = current.find( MARKER )
markerpos1 = current1.find( MARKER )
if markerpos >= 0: print "Cython", markerpos
if markerpos1 >= 0: print "Python", markerpos1, " ", len( current1)
count = count + 1
if count == 5: break
#fl.close()
fclose(cfl)
fl.close()
return ii_frame, frame_data