добавлять к файлу, когда он доступен [дубликат]

Аналогичный ответ на тот, который предоставлен Temani Afif, но с использованием svg вместо изображения (поэтому нет необходимости в дополнительном запросе).

Кроме того, легче адаптировать его к произвольным пропорциям

.container {
  height: 150px;
  background-color: lightblue;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px;
}

.aspectRatio {
  display: grid;
  background-color: yellow;
  height: 50%;
}
.aspectRatio svg {
  height: 100%;
  border: solid 1px red;
  animation: resize 1s infinite;
}
.aspectRatio > * {
  grid-area: 1 / 1 / 2 / 2;
}

@keyframes resize {
  from {height: 100%;}
  to {height: 99.9%;}
}
<div class="container">
  <div class="aspectRatio">
    <svg viewBox="0 0 1 1"></svg>
    <div class="inner">square</div>
  </div>
</div>
<div class="container">
  <div class="aspectRatio">
    <svg viewBox="0 0 4 3"></svg>
    <div class="inner">ratio 4/3</div>
  </div>
</div>

2
задан shaun 7 June 2016 в 22:17
поделиться

1 ответ

Код Я закончил использование после некоторой инструкции из комментариев.

var delInterval = setInterval(del(), 1000);

function del(){
    fs.open(filePath, 'r+', function(err, fd){
        if (err && err.code === 'EBUSY'){
            //do nothing till next loop
        } else if (err && err.code === 'ENOENT'){
            console.log(filePath, 'deleted');
            clearInterval(delInterval);
        } else {
            fs.close(fd, function(){
                fs.unlink(filePath, function(err){
                    if(err){
                    } else {
                    console.log(filePath, 'deleted');
                    clearInterval(delInterval);
                    }
                });
            });
        }
    });
}
6
ответ дан shaun 20 August 2018 в 16:02
поделиться
Другие вопросы по тегам:

Похожие вопросы: