33 * can be found in the LICENSE.txt file in the project root.
44 */
55
6- import InputStream from './InputStream .js' ;
7- import fs from "fs " ;
6+ import CharStream from "./CharStream .js" ;
7+ import FileStream from "./FileStream.js " ;
88
99/**
1010 * Utility functions to create InputStreams from various sources.
@@ -16,7 +16,7 @@ import fs from "fs";
1616export default {
1717 // Creates an InputStream from a string.
1818 fromString : function ( str ) {
19- return new InputStream ( str , true ) ;
19+ return new CharStream ( str , true ) ;
2020 } ,
2121
2222 /**
@@ -30,7 +30,7 @@ export default {
3030 fromBlob : function ( blob , encoding , onLoad , onError ) {
3131 const reader = new window . FileReader ( ) ;
3232 reader . onload = function ( e ) {
33- const is = new InputStream ( e . target . result , true ) ;
33+ const is = new CharStream ( e . target . result , true ) ;
3434 onLoad ( is ) ;
3535 } ;
3636 reader . onerror = onError ;
@@ -43,7 +43,7 @@ export default {
4343 * encoding is null).
4444 */
4545 fromBuffer : function ( buffer , encoding ) {
46- return new InputStream ( buffer . toString ( encoding ) , true ) ;
46+ return new CharStream ( buffer . toString ( encoding ) , true ) ;
4747 } ,
4848
4949 /** Asynchronously creates an InputStream from a file on disk given
@@ -53,13 +53,7 @@ export default {
5353 * Invokes callback(error, result) on completion.
5454 */
5555 fromPath : function ( path , encoding , callback ) {
56- fs . readFile ( path , encoding , function ( err , data ) {
57- let is = null ;
58- if ( data !== null ) {
59- is = new InputStream ( data , true ) ;
60- }
61- callback ( err , is ) ;
62- } ) ;
56+ FileStream . fromPath ( path , encoding , callback ) ;
6357 } ,
6458
6559 /**
@@ -68,7 +62,6 @@ export default {
6862 * 'utf8' if encoding is null).
6963 */
7064 fromPathSync : function ( path , encoding ) {
71- const data = fs . readFileSync ( path , encoding ) ;
72- return new InputStream ( data , true ) ;
65+ return new FileStream ( path , encoding ) ;
7366 }
7467} ;
0 commit comments