Last active
August 29, 2015 14:01
-
-
Save darkowlzz/0e597d4ef4e930470106 to your computer and use it in GitHub Desktop.
synchronous Read using nsIChannel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { Cu, Ci } = require('chrome'); | |
| const { NetUtil } = Cu.import('resource://gre/modules/NetUtil.jsm'); | |
| let charset = 'UTF-8'; | |
| let channel = NetUtil.newChannel('chrome://foo/content/test-file.txt', charset, null); | |
| // `channel` obtained is an nsIChannel object. Open the channel synchronously. | |
| let stream = channel.open(); | |
| // Get the stream length | |
| let count = stream.available(); | |
| // Read the input stream and convert to string. | |
| let data = NetUtil.readInputStreamToString(stream, count, { charset: charset }); | |
| // Close the input stream | |
| stream.close(); | |
| console.log(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment