#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2022/10/16 10:05:28

@author: LiuKuan
@copyright: Apache License, Version 2.0
'''
# ===============================================================================
r'''
'''
# ===============================================================================
__all__ = ['file_read_text', 'file_write_text', 'file_read_lines', 'file_write_lines',
           'file_read_bin', 'file_write_bin',
           'file_text_reader', 'file_bin_reader',
           'file_bin_writer', 'file_text_writer'
           ]

def file_text_reader(fname, encoding='utf8'):
    return open(fname, mode='r', encoding=encoding)

def file_bin_reader(fname):
    return open(fname, mode='rb')

def file_text_writer(fname, encoding='utf8'):
    return open(fname, mode='w', encoding=encoding)

def file_bin_writer(fname):
    return open(fname, mode='wb')

def file_read_text(fname, encoding='utf8'):
    with open(fname, mode='r', encoding=encoding) as f:
        return f.read()

def file_write_text(text, fname, encoding='utf8'):
    with open(fname, mode='w', encoding=encoding) as f:
        f.write(text)

def file_read_lines(fname, encoding='utf8', strip = True):
    with open(fname, mode='r', encoding=encoding) as f:
        for line in f:
            if strip:
                line = line.strip()
            yield line

def file_write_lines(lines, fname, encoding='utf8', line_append='\n'):
    with open(fname, mode='w', encoding=encoding) as f:
        for line in lines:
            f.write(line + line_append)

def file_read_bin(fname):
    with open(fname, mode='rb') as f:
        return f.read()

def file_write_bin(data, fname):
    with open(fname, mode='wb') as f:
        f.write(data)

