diff --git a/README.md b/README.md index 44b4e06..f4433a7 100644 --- a/README.md +++ b/README.md @@ -167,8 +167,8 @@ the callback in a call to webshot. siteType 'url' siteType indicates whether the content needs to be requested ('url'), - loaded locally ('file'), or is being provided directly as a string - ('html'). + loaded locally ('file'), or is being provided directly as a string or + buffer, see htmlEncoding option ('html'). renderDelay @@ -203,6 +203,11 @@ the callback in a call to webshot. false Captures the page area containing the provided selector and saves it to file. + + htmlEncoding + utf-8 + If passing HTML the encoding to be used. If none, the html is parsed as a buffer. + diff --git a/lib/options.js b/lib/options.js index b7c6ce0..f277b7e 100644 --- a/lib/options.js +++ b/lib/options.js @@ -26,6 +26,7 @@ exports.phantom = { , cookies: [] , captureSelector: false , zoomFactor: 1 +, htmlEncoding: 'utf-8' }; // Options that are just passed to the phantom page object diff --git a/lib/webshot.js b/lib/webshot.js index 5b8a21c..903a528 100644 --- a/lib/webshot.js +++ b/lib/webshot.js @@ -96,7 +96,10 @@ module.exports = function() { if (options.siteType === 'html') { var obj = tmp.fileSync(); var tmpPath = obj.name; - fs.writeSync(obj.fd, site, null, 'utf-8'); + if (options.htmlEncoding) + fs.writeSync(obj.fd, site, null, options.htmlEncoding); + else + fs.writeSync(obj.fd, site); fs.close(obj.fd); options.siteType = 'file'; site = tmpPath; diff --git a/test/options/siteType.js b/test/options/siteType.js index ea59ba0..d392d6f 100644 --- a/test/options/siteType.js +++ b/test/options/siteType.js @@ -9,6 +9,19 @@ var webshot = require('../../lib/webshot') describe('siteType', function() { this.timeout(20000); + it('takes a screenshot of the provided buffer', function(done) { + webshot(new Buffer('This is a test'), + pngOutput, + {siteType: 'html', htmlEncoding: null}, + function(err) { + if (err) return done(err); + fs.exists(pngOutput, function(exists) { + exists.should.equal(true); + done(); + }); + }); + }); + it('takes a screenshot of the provided html', function(done) { webshot('This is a test', pngOutput,