diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h
index bf3e691bd87292ce6dc62da44050f8b791814fd1..08f926f4030fab1c8c3ca1a573575ce6ad729ebc 100644
--- a/cc3200/mpconfigport.h
+++ b/cc3200/mpconfigport.h
@@ -55,6 +55,7 @@
 #define MICROPY_FLOAT_IMPL                          (MICROPY_FLOAT_IMPL_NONE)
 #define MICROPY_OPT_COMPUTED_GOTO                   (0)
 #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE    (0)
+#define MICROPY_READER_FATFS                        (1)
 #ifndef DEBUG // we need ram on the launchxl while debugging
 #define MICROPY_CPYTHON_COMPAT                      (1)
 #else
diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld
index 546ffd8c5da0426967a4a1daf71eb746bd61d5d7..a6a4b930bb71e2e12b483b3a06c09a3069309c44 100644
--- a/esp8266/esp8266.ld
+++ b/esp8266/esp8266.ld
@@ -92,6 +92,7 @@ SECTIONS
         *py/formatfloat.o*(.literal* .text*)
         *py/frozenmod.o*(.literal* .text*)
         *py/gc.o*(.literal* .text*)
+        *py/reader*.o*(.literal* .text*)
         *py/lexer*.o*(.literal* .text*)
         *py/malloc*.o*(.literal* .text*)
         *py/map*.o*(.literal* .text*)
diff --git a/esp8266/esp8266_512k.ld b/esp8266/esp8266_512k.ld
index e744d0f4645d2dd2a257ccce4a8302df5c3ce285..2bffcab80dfbc990733c325cb5abe651341652dc 100644
--- a/esp8266/esp8266_512k.ld
+++ b/esp8266/esp8266_512k.ld
@@ -92,6 +92,7 @@ SECTIONS
         *py/formatfloat.o*(.literal* .text*)
         *py/frozenmod.o*(.literal* .text*)
         *py/gc.o*(.literal* .text*)
+        *py/reader*.o*(.literal* .text*)
         *py/lexer*.o*(.literal* .text*)
         *py/malloc*.o*(.literal* .text*)
         *py/map*.o*(.literal* .text*)
diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h
index 602b3e9c81fb1a66f648cbeb304b8c14fee0288a..adbec5d0d8872747e6e04dc862b6bc2d05ec8d28 100644
--- a/esp8266/mpconfigport.h
+++ b/esp8266/mpconfigport.h
@@ -16,6 +16,7 @@
 #define MICROPY_MEM_STATS           (0)
 #define MICROPY_DEBUG_PRINTERS      (1)
 #define MICROPY_DEBUG_PRINTER_DEST  mp_debug_print
+#define MICROPY_READER_FATFS        (1)
 #define MICROPY_ENABLE_GC           (1)
 #define MICROPY_STACK_CHECK         (1)
 #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
diff --git a/examples/embedding/mpconfigport_minimal.h b/examples/embedding/mpconfigport_minimal.h
index 90011b3f81035eeee076632fbbe691de2df145ab..48d20085831fd59449311b4ebec7a8c4132449a3 100644
--- a/examples/embedding/mpconfigport_minimal.h
+++ b/examples/embedding/mpconfigport_minimal.h
@@ -33,6 +33,7 @@
 #define MICROPY_COMP_CONST          (0)
 #define MICROPY_MEM_STATS           (0)
 #define MICROPY_DEBUG_PRINTERS      (0)
+#define MICROPY_READER_POSIX        (1)
 #define MICROPY_HELPER_REPL         (1)
 #define MICROPY_HELPER_LEXER_UNIX   (1)
 #define MICROPY_ENABLE_SOURCE_LINE  (0)
diff --git a/extmod/vfs_fat_reader.c b/extmod/vfs_fat_reader.c
new file mode 100644
index 0000000000000000000000000000000000000000..7a00f18de34fa41d4d665ddd94a1dc1bb792894a
--- /dev/null
+++ b/extmod/vfs_fat_reader.c
@@ -0,0 +1,88 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2016 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <assert.h>
+
+#include "py/mperrno.h"
+#include "py/reader.h"
+
+#if MICROPY_READER_FATFS
+
+#include "lib/fatfs/ff.h"
+#include "extmod/vfs_fat_file.h"
+
+typedef struct _mp_reader_fatfs_t {
+    FIL fp;
+    uint16_t len;
+    uint16_t pos;
+    byte buf[20];
+} mp_reader_fatfs_t;
+
+STATIC mp_uint_t mp_reader_fatfs_readbyte(void *data) {
+    mp_reader_fatfs_t *reader = (mp_reader_fatfs_t*)data;
+    if (reader->pos >= reader->len) {
+        if (reader->len < sizeof(reader->buf)) {
+            return MP_READER_EOF;
+        } else {
+            UINT n;
+            f_read(&reader->fp, reader->buf, sizeof(reader->buf), &n);
+            if (n == 0) {
+                return MP_READER_EOF;
+            }
+            reader->len = n;
+            reader->pos = 0;
+        }
+    }
+    return reader->buf[reader->pos++];
+}
+
+STATIC void mp_reader_fatfs_close(void *data) {
+    mp_reader_fatfs_t *reader = (mp_reader_fatfs_t*)data;
+    f_close(&reader->fp);
+    m_del_obj(mp_reader_fatfs_t, reader);
+}
+
+int mp_reader_new_file(mp_reader_t *reader, const char *filename) {
+    mp_reader_fatfs_t *rf = m_new_obj_maybe(mp_reader_fatfs_t);
+    if (rf == NULL) {
+        return MP_ENOMEM;
+    }
+    FRESULT res = f_open(&rf->fp, filename, FA_READ);
+    if (res != FR_OK) {
+        return fresult_to_errno_table[res];
+    }
+    UINT n;
+    f_read(&rf->fp, rf->buf, sizeof(rf->buf), &n);
+    rf->len = n;
+    rf->pos = 0;
+    reader->data = rf;
+    reader->readbyte = mp_reader_fatfs_readbyte;
+    reader->close = mp_reader_fatfs_close;
+    return 0; // success
+}
+
+#endif
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 3945a1a5ab33c0ff21c35a08906ef84a4f9c7e2b..1980e649caf743bd99f40880d737499fc5e10650 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -381,6 +381,16 @@
 /*****************************************************************************/
 /* Python internal features                                                  */
 
+// Whether to use the POSIX reader for importing files
+#ifndef MICROPY_READER_POSIX
+#define MICROPY_READER_POSIX (0)
+#endif
+
+// Whether to use the FatFS reader for importing files
+#ifndef MICROPY_READER_FATFS
+#define MICROPY_READER_FATFS (0)
+#endif
+
 // Hook for the VM at the start of the opcode loop (can contain variable
 // definitions usable by the other hook functions)
 #ifndef MICROPY_VM_HOOK_INIT
diff --git a/py/persistentcode.c b/py/persistentcode.c
index 31f147a0957c3438a91343a1ebbace52cba66cd6..99b01f8e2721c91b174c70793d7cd460127f5a24 100644
--- a/py/persistentcode.c
+++ b/py/persistentcode.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <assert.h>
 
+#include "py/reader.h"
 #include "py/emitglue.h"
 #include "py/persistentcode.h"
 #include "py/bc.h"
@@ -98,19 +99,19 @@ STATIC void extract_prelude(const byte **ip, const byte **ip2, bytecode_prelude_
 #include "py/bc0.h"
 
 STATIC int read_byte(mp_reader_t *reader) {
-    return reader->read_byte(reader->data);
+    return reader->readbyte(reader->data);
 }
 
 STATIC void read_bytes(mp_reader_t *reader, byte *buf, size_t len) {
     while (len-- > 0) {
-        *buf++ = reader->read_byte(reader->data);
+        *buf++ = reader->readbyte(reader->data);
     }
 }
 
 STATIC mp_uint_t read_uint(mp_reader_t *reader) {
     mp_uint_t unum = 0;
     for (;;) {
-        byte b = reader->read_byte(reader->data);
+        byte b = reader->readbyte(reader->data);
         unum = (unum << 7) | (b & 0x7f);
         if ((b & 0x80) == 0) {
             break;
@@ -214,128 +215,28 @@ mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) {
     if (header[2] != MPY_FEATURE_FLAGS || header[3] > mp_small_int_bits()) {
         mp_raise_ValueError("incompatible .mpy file");
     }
-    return load_raw_code(reader);
-}
-
-typedef struct _mp_mem_reader_t {
-    const byte *cur;
-    const byte *end;
-} mp_mem_reader_t;
-
-STATIC mp_uint_t mp_mem_reader_next_byte(void *br_in) {
-    mp_mem_reader_t *br = br_in;
-    if (br->cur < br->end) {
-        return *br->cur++;
-    } else {
-        return (mp_uint_t)-1;
-    }
+    mp_raw_code_t *rc = load_raw_code(reader);
+    reader->close(reader->data);
+    return rc;
 }
 
 mp_raw_code_t *mp_raw_code_load_mem(const byte *buf, size_t len) {
-    mp_mem_reader_t mr = {buf, buf + len};
-    mp_reader_t reader = {&mr, mp_mem_reader_next_byte};
-    return mp_raw_code_load(&reader);
-}
-
-// here we define mp_raw_code_load_file depending on the port
-// TODO abstract this away properly
-
-#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || defined(__unix__)
-// unix file reader
-
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-typedef struct _mp_lexer_file_buf_t {
-    int fd;
-    byte buf[20];
-    mp_uint_t len;
-    mp_uint_t pos;
-} mp_lexer_file_buf_t;
-
-STATIC mp_uint_t file_buf_next_byte(void *fb_in) {
-    mp_lexer_file_buf_t *fb = fb_in;
-    if (fb->pos >= fb->len) {
-        if (fb->len == 0) {
-            return (mp_uint_t)-1;
-        } else {
-            int n = read(fb->fd, fb->buf, sizeof(fb->buf));
-            if (n <= 0) {
-                fb->len = 0;
-                return (mp_uint_t)-1;
-            }
-            fb->len = n;
-            fb->pos = 0;
-        }
-    }
-    return fb->buf[fb->pos++];
-}
-
-mp_raw_code_t *mp_raw_code_load_file(const char *filename) {
-    mp_lexer_file_buf_t fb;
-    fb.fd = open(filename, O_RDONLY, 0644);
-    int n = read(fb.fd, fb.buf, sizeof(fb.buf));
-    fb.len = n;
-    fb.pos = 0;
     mp_reader_t reader;
-    reader.data = &fb;
-    reader.read_byte = file_buf_next_byte;
-    mp_raw_code_t *rc = mp_raw_code_load(&reader);
-    close(fb.fd);
-    return rc;
-}
-
-#elif defined(__thumb2__) || defined(__xtensa__)
-// fatfs file reader (assume thumb2 arch uses fatfs...)
-
-#include "lib/fatfs/ff.h"
-
-typedef struct _mp_lexer_file_buf_t {
-    FIL fp;
-    byte buf[20];
-    uint16_t len;
-    uint16_t pos;
-} mp_lexer_file_buf_t;
-
-STATIC mp_uint_t file_buf_next_byte(void *fb_in) {
-    mp_lexer_file_buf_t *fb = fb_in;
-    if (fb->pos >= fb->len) {
-        if (fb->len < sizeof(fb->buf)) {
-            return (mp_uint_t)-1;
-        } else {
-            UINT n;
-            f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n);
-            if (n == 0) {
-                return (mp_uint_t)-1;
-            }
-            fb->len = n;
-            fb->pos = 0;
-        }
+    if (!mp_reader_new_mem(&reader, buf, len, 0)) {
+        m_malloc_fail(BYTES_PER_WORD); // we need to raise a MemoryError
     }
-    return fb->buf[fb->pos++];
+    return mp_raw_code_load(&reader);
 }
 
 mp_raw_code_t *mp_raw_code_load_file(const char *filename) {
-    mp_lexer_file_buf_t fb;
-    /*FRESULT res =*/ f_open(&fb.fp, filename, FA_READ);
-    UINT n;
-    f_read(&fb.fp, fb.buf, sizeof(fb.buf), &n);
-    fb.len = n;
-    fb.pos = 0;
-
     mp_reader_t reader;
-    reader.data = &fb;
-    reader.read_byte = file_buf_next_byte;
-    mp_raw_code_t *rc = mp_raw_code_load(&reader);
-
-    f_close(&fb.fp);
-
-    return rc;
+    int ret = mp_reader_new_file(&reader, filename);
+    if (ret != 0) {
+        mp_raise_OSError(ret);
+    }
+    return mp_raw_code_load(&reader);
 }
 
-#endif
-
 #endif // MICROPY_PERSISTENT_CODE_LOAD
 
 #if MICROPY_PERSISTENT_CODE_SAVE
diff --git a/py/persistentcode.h b/py/persistentcode.h
index 8859bc577a0b80daef2ab7a4318cb04b4bbf4e28..d04e0b633089ffe5346173f85be5fc36069c89f6 100644
--- a/py/persistentcode.h
+++ b/py/persistentcode.h
@@ -26,13 +26,9 @@
 #ifndef MICROPY_INCLUDED_PY_PERSISTENTCODE_H
 #define MICROPY_INCLUDED_PY_PERSISTENTCODE_H
 
-#include "py/obj.h"
-
-typedef struct _mp_reader_t {
-    void *data;
-    mp_uint_t (*read_byte)(void *data);
-    void (*close)(void *data);
-} mp_reader_t;
+#include "py/mpprint.h"
+#include "py/reader.h"
+#include "py/emitglue.h"
 
 mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader);
 mp_raw_code_t *mp_raw_code_load_mem(const byte *buf, size_t len);
diff --git a/py/py.mk b/py/py.mk
index b0962d178f5fbae1dc91efaf0a4b2de09d2e9a62..4630c21a9f8259adea3596c4205ba92de3175002 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -113,6 +113,7 @@ PY_O_BASENAME = \
 	mpprint.o \
 	unicode.o \
 	mpz.o \
+	reader.o \
 	lexer.o \
 	lexerstr.o \
 	lexerunix.o \
@@ -228,6 +229,7 @@ PY_O_BASENAME = \
 	../extmod/vfs_fat_ffconf.o \
 	../extmod/vfs_fat_diskio.o \
 	../extmod/vfs_fat_file.o \
+	../extmod/vfs_fat_reader.o \
 	../extmod/vfs_fat_lexer.o \
 	../extmod/vfs_fat_misc.o \
 	../extmod/utime_mphal.o \
diff --git a/py/reader.c b/py/reader.c
new file mode 100644
index 0000000000000000000000000000000000000000..d14fc416ca9eb8ca75b3b1a15ff5ed11c229d1a5
--- /dev/null
+++ b/py/reader.c
@@ -0,0 +1,146 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2016 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <assert.h>
+
+#include "py/mperrno.h"
+#include "py/reader.h"
+
+typedef struct _mp_reader_mem_t {
+    size_t free_len; // if >0 mem is freed on close by: m_free(beg, free_len)
+    const byte *beg;
+    const byte *cur;
+    const byte *end;
+} mp_reader_mem_t;
+
+STATIC mp_uint_t mp_reader_mem_readbyte(void *data) {
+    mp_reader_mem_t *reader = (mp_reader_mem_t*)data;
+    if (reader->cur < reader->end) {
+        return *reader->cur++;
+    } else {
+        return MP_READER_EOF;
+    }
+}
+
+STATIC void mp_reader_mem_close(void *data) {
+    mp_reader_mem_t *reader = (mp_reader_mem_t*)data;
+    if (reader->free_len > 0) {
+        m_del(char, (char*)reader->beg, reader->free_len);
+    }
+    m_del_obj(mp_reader_mem_t, reader);
+}
+
+bool mp_reader_new_mem(mp_reader_t *reader, const byte *buf, size_t len, size_t free_len) {
+    mp_reader_mem_t *rm = m_new_obj_maybe(mp_reader_mem_t);
+    if (rm == NULL) {
+        return false;
+    }
+    rm->free_len = free_len;
+    rm->beg = buf;
+    rm->cur = buf;
+    rm->end = buf + len;
+    reader->data = rm;
+    reader->readbyte = mp_reader_mem_readbyte;
+    reader->close = mp_reader_mem_close;
+    return true;
+}
+
+#if MICROPY_READER_POSIX
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+
+typedef struct _mp_reader_posix_t {
+    bool close_fd;
+    int fd;
+    size_t len;
+    size_t pos;
+    byte buf[20];
+} mp_reader_posix_t;
+
+STATIC mp_uint_t mp_reader_posix_readbyte(void *data) {
+    mp_reader_posix_t *reader = (mp_reader_posix_t*)data;
+    if (reader->pos >= reader->len) {
+        if (reader->len == 0) {
+            return MP_READER_EOF;
+        } else {
+            int n = read(reader->fd, reader->buf, sizeof(reader->buf));
+            if (n <= 0) {
+                reader->len = 0;
+                return MP_READER_EOF;
+            }
+            reader->len = n;
+            reader->pos = 0;
+        }
+    }
+    return reader->buf[reader->pos++];
+}
+
+STATIC void mp_reader_posix_close(void *data) {
+    mp_reader_posix_t *reader = (mp_reader_posix_t*)data;
+    if (reader->close_fd) {
+        close(reader->fd);
+    }
+    m_del_obj(mp_reader_posix_t, reader);
+}
+
+STATIC int mp_reader_new_file_from_fd(mp_reader_t *reader, int fd, bool close_fd) {
+    mp_reader_posix_t *rp = m_new_obj_maybe(mp_reader_posix_t);
+    if (rp == NULL) {
+        if (close_fd) {
+            close(fd);
+        }
+        return MP_ENOMEM;
+    }
+    rp->close_fd = close_fd;
+    rp->fd = fd;
+    int n = read(rp->fd, rp->buf, sizeof(rp->buf));
+    if (n == -1) {
+        if (close_fd) {
+            close(fd);
+        }
+        return errno;
+    }
+    rp->len = n;
+    rp->pos = 0;
+    reader->data = rp;
+    reader->readbyte = mp_reader_posix_readbyte;
+    reader->close = mp_reader_posix_close;
+    return 0; // success
+}
+
+int mp_reader_new_file(mp_reader_t *reader, const char *filename) {
+    int fd = open(filename, O_RDONLY, 0644);
+    if (fd < 0) {
+        return errno;
+    }
+    return mp_reader_new_file_from_fd(reader, fd, true);
+}
+
+#endif
diff --git a/py/reader.h b/py/reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..f39cc90f8e339252bd7f5c09f4e24f9606711d4f
--- /dev/null
+++ b/py/reader.h
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2016 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef MICROPY_INCLUDED_PY_READER_H
+#define MICROPY_INCLUDED_PY_READER_H
+
+#include "py/obj.h"
+
+// the readbyte function must return the next byte in the input stream
+// it must return MP_READER_EOF if end of stream
+// it can be called again after returning MP_READER_EOF, and in that case must return MP_READER_EOF
+#define MP_READER_EOF ((mp_uint_t)(-1))
+
+typedef struct _mp_reader_t {
+    void *data;
+    mp_uint_t (*readbyte)(void *data);
+    void (*close)(void *data);
+} mp_reader_t;
+
+bool mp_reader_new_mem(mp_reader_t *reader, const byte *buf, size_t len, size_t free_len);
+int mp_reader_new_file(mp_reader_t *reader, const char *filename);
+
+#endif // MICROPY_INCLUDED_PY_READER_H
diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h
index 264db3029d00ff4c298e3ef5ed8fe1f9ad91d276..3eec0fcce01f100a3eada92d727a214a1fce7093 100644
--- a/stmhal/mpconfigport.h
+++ b/stmhal/mpconfigport.h
@@ -51,6 +51,7 @@
 #define MICROPY_OPT_COMPUTED_GOTO   (1)
 #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
 #define MICROPY_OPT_MPZ_BITWISE     (1)
+#define MICROPY_READER_FATFS        (1)
 
 // fatfs configuration used in ffconf.h
 #define MICROPY_FATFS_ENABLE_LFN       (1)
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index f4f8d2d2084c114714f2f4a8a2e96e9ef6a82100..86e460566d20ebf182f0e31fcd5f00940f60ca18 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -54,6 +54,7 @@
 // Printing debug to stderr may give tests which
 // check stdout a chance to pass, etc.
 #define MICROPY_DEBUG_PRINTER_DEST  mp_stderr_print
+#define MICROPY_READER_POSIX        (1)
 #define MICROPY_USE_READLINE_HISTORY (1)
 #define MICROPY_HELPER_REPL         (1)
 #define MICROPY_REPL_EMACS_KEYS     (1)