Moved screenshot functions into Device's class.
Summary: I have moved the screenshot functions from ScreenCaptureButtons to the Device classes. I have slightly rewritten them so that they return a Promise which resolves to a Buffer. The Buffer can then be saved to a file or converted to a data Blob. I have removed streaming and simply loaded the image into memory. Once the image is in memory it can be manipulated for various tasks i.e. written to a file, or displayed in the app. iOS screenshots had to be rewritten. I now save the image to a temp folder, load it into the apps memory, and then remove the temp image. Reviewed By: jknoxville Differential Revision: D16939901 fbshipit-source-id: 3e39a5aeda8d48829ac5a8ff912a98f110341c07
This commit is contained in:
committed by
Facebook Github Bot
parent
263b47f82f
commit
7def9bb681
31
src/utils/screenshot.tsx
Normal file
31
src/utils/screenshot.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2018-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
/**
|
||||
* Writes a buffer to a specified file path.
|
||||
* Returns a Promise which resolves to the file path.
|
||||
*/
|
||||
export const writeBufferToFile = (filePath: string, buffer: Buffer) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(filePath, buffer, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(filePath);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a Blob from a Buffer
|
||||
*/
|
||||
export const bufferToBlob = (buffer: Buffer): Blob => {
|
||||
return new Blob([buffer]);
|
||||
};
|
||||
Reference in New Issue
Block a user