How to use the react-native-fs.appendFile function in react-native-fs

To help you get started, we’ve selected a few react-native-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crownstone / CrownstoneApp / js / logging / LogUtil.ts View on Github external
let filePath = logPath + '/' + filename;

  // create string
  let str = '' + new Date().valueOf() + ' - ' + new Date() + " -";
  for (let i = 0; i < arguments.length; i++) {
    if (typeof arguments[i] === 'object' || Array.isArray(arguments[i])) {
      str += " " + JSON.stringify(arguments[i])
    }
    else {
      str += " " + arguments[i]
    }
  }
  str += " \n";

  // write the file
  RNFS.appendFile(filePath, str, 'utf8')
    .then((success) => {})
    .catch((err) => {})
}
github celo-org / celo-monorepo / packages / mobile / src / utils / Logger.ts View on Github external
try {
      this.showMessage('Creating combined log...')
      const gethLogsSrc = this.getGethLogFilePath()
      const rnLogsSrc = this.getReactNativeLogsFilePath()
      // The RN library we are using only supports one file attachment. In the longer run, we should
      // either find a new library or write a new one. For now, we will put the logs in one file.
      // Longer run, we will go for a multi-attachment route. The other problem with our current approach
      // is that we have to write this log file into a world-readable directory. Android has a concept of
      // one time file access permissions which we cannot use here since the library we are using it
      // does not understand that.
      const combinedLogsPath = this.getCombinedLogsFilePath()
      await RNFS.writeFile(combinedLogsPath, '========React Native Logs========\n')
      if (await RNFS.exists(rnLogsSrc)) {
        await RNFS.appendFile(combinedLogsPath, await RNFS.readFile(rnLogsSrc))
      }
      await RNFS.appendFile(combinedLogsPath, '\n\n========Geth Logs========\n')
      if (await RNFS.exists(gethLogsSrc)) {
        await RNFS.appendFile(combinedLogsPath, await RNFS.readFile(gethLogsSrc))
      }
      return combinedLogsPath
    } catch (e) {
      this.showError('Failed to  copy files: ' + e)
      return false
    }
  }
github cjdell / react-native-fs-test / index.common.js View on Github external
}).then(() => {
      return RNFS.appendFile(f2, 'baz 𝌆 bar © foo', 'utf8');
    }).then(() => {
      return RNFS.readFile(f1, 'utf8').then(contents => {
github cjdell / react-native-fs-test / index.common.js View on Github external
}).then(() => {
      return RNFS.appendFile(f1, 'baz 𝌆 bar © foo', 'utf8');
    }).then(() => {
      return RNFS.appendFile(f2, 'baz 𝌆 bar © foo', 'utf8');
github EdgeApp / edge-react-gui / src / util / logger.js View on Github external
async function writeLog (content) {
  try {
    const exists = await RNFS.exists(path)

    if (exists) {
      numWrites++
      if (numWrites > NUM_WRITES_BEFORE_ROTATE_CHECK) {
        if (await isLogFileLimitExceeded(path)) {
          await rotateLogs()
          numWrites = 0
        }
      }
      return await RNFS.appendFile(path, '\n' + content)
    } else {
      return await RNFS.writeFile(path, content)
    }
  } catch (e) {
    global.clog((e && e.message) || e)
  }
}
github celo-org / celo-monorepo / packages / react-components / services / ReactNativeLogger.ts View on Github external
const writeLog = (level: string, message: string) => {
      const timestamp = new Date().toISOString()
      RNFS.appendFile(logFilePath, `${level} [${timestamp}] ${message}\n`, 'utf8').catch(
        (error) => {
          oldDebug(`Failed to write to ${logFilePath}`, error)
        }
      )
    }
github laurent22 / joplin / ReactNativeClient / lib / fs-driver-rn.js View on Github external
appendFile(path, string, encoding = 'base64') {
		return RNFS.appendFile(path, string, encoding);
	}
github EdgeApp / edge-react-gui / src / lib / perfLogger.js View on Github external
export const perfLogger = (store: Store) => (next: Next) => (action: Action) => {
  const start = Date.now()
  const result = next(action)
  const end = Date.now()

  RNFS.appendFile(perfLoggerCSV, `${action.type},${start},${end}\n`)

  return result
}