mosquito/aiofile

LineReader issue on Windows

Closed this issue · 0 comments

When reading a file in windows the last line is not read correctly. Here is the example code:

async def read_text():
    path = os.getcwd()
    myfile = os.path.join(path, 'dummy.txt')
    a = 1
    async with AIOFile(myfile, 'r') as afp:
        async for line in LineReader(afp):
            print(a, ': ', line[:-1])
            a += 1

Where the dummy.txt file is this:

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
This is line 6
This is line 7
This is line 8

including the extra line at the end. The output is:

1 :  This is line 1
2 :  This is line 2
3 :  This is line 3
4 :  This is line 4
5 :  This is line 5
6 :  This is line 6
7 :  This is line 7
8 :  This is line 8
9 :  line 8
10 :

If the extra line is removed, the output is this:

1 :  This is line 1
2 :  This is line 2
3 :  This is line 3
4 :  This is line 4
5 :  This is line 5
6 :  This is line 6
7 :  This is line 7
8 :  This is line 8 line