Translate more files, fix outdated remote.md section

Translate content-tracing(50%), remote docs.
Fix `Remote buffer` section as outdated.
This commit is contained in:
Plusb Preco 2015-08-21 11:33:02 +09:00
parent 172cc22d90
commit 351dc4ed6b
3 changed files with 43 additions and 165 deletions

View file

@ -82,55 +82,6 @@ when the `close` event was emitted, exceptions would be raised in the main proce
Generally, unless you are clear what you are doing, you should always avoid
passing callbacks to the main process.
## Remote buffer
An instance of node's `Buffer` is an object, so when you get a `Buffer` from
the main process, what you get is indeed a remote object (let's call it remote
buffer), and everything would just follow the rules of remote objects.
However you should remember that although a remote buffer behaves like the real
`Buffer`, it's not a `Buffer` at all. If you pass a remote buffer to node APIs
that accept a `Buffer`, you should assume the remote buffer would be treated
like a normal object, instead of a `Buffer`.
For example, you can call `BrowserWindow.capturePage` in the renderer process, which
returns a `Buffer` by calling the passed callback:
```javascript
var remote = require('remote');
var fs = require('fs');
remote.getCurrentWindow().capturePage(function(image) {
var buf = image.toPng();
fs.writeFile('/tmp/screenshot.png', buf, function(err) {
console.log(err);
});
});
```
But you may be surprised to find that the file written was corrupted. This is
because when you called `fs.writeFile`, thinking that `buf` was a `Buffer` when
in fact it was a remote buffer, and it was converted to string before it was
written to the file. Since `buf` contained binary data and could not be represented
by a UTF-8 encoded string, the written file was corrupted.
The work-around is to write the `buf` in the main process, where it is a real
`Buffer`:
```javascript
var remote = require('remote');
remote.getCurrentWindow().capturePage(function(image) {
var buf = image.toPng();
remote.require('fs').writeFile('/tmp/screenshot.png', buf, function(err) {
console.log(err);
});
});
```
The same thing could happen for all native types, but usually it would just
throw a type error. The `Buffer` deserves your special attention because it
might be converted to string, and APIs accepting `Buffer` usually accept string
too, and data corruption could happen when it contains binary data.
## remote.require(module)
* `module` String