Added read from file and buffer
changed buf to buffer